Solved

Timer problem vb6

Posted on 2013-11-16
8
322 Views
Last Modified: 2013-11-16
I am not experienced using a timer i am trying to pause a procedure a number of second passed
Private Sub Command1_Click()
Chill 10
End Sub


Sub Chill(seconds As Integer)
Dim i As Integer
Dim counter As Integer
seconds = seconds * 1000
Timer2.Interval = 1000
Timer2.Enabled = True
For i = 1 To seconds Step 1000
counter = counter + 1000
Next i
 Command1.Visible = False
Timer2.Enabled = False
End Sub
What is the problem. the above code does not work. it fires immediately
0
Comment
Question by:isnoend2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39653484
You cannot use the timer to pause as such.

When you start the timer, it will fire a Timer event after the interval has elapsed and you need to put some code in the event to do what you want to do after the interval. This will hide the Command button for a second.

Option Explicit

Private Sub Command1_Click()
    Command1.Visible = False
    Chill 10
End Sub


Sub Chill(seconds As Integer)
    Timer2.Interval = 1000
    Timer2.Enabled = True
End Sub

Sub Timer2_Timer()
    Command1.Visible = True
    Timer2.Enabled = False
End Sub

Open in new window

0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39653487
Just do
' At the top of your form
Declare Sub Sleep Lib "kernel32" (ByVal milliseconds As Long)

and then
Sleep 10000 ' Time in miliseconds
0
 

Author Comment

by:isnoend2001
ID: 39653494
thanks  MartinLiss, but i have been using sleep, but don't want the app to freeze

Thanks  GrahamSkan, but it does not work
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:isnoend2001
ID: 39653500
Must have copied something wrong. thanks
0
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39653501
this line is not needed

Timer2.Enabled = True

' Visual Basic 6.0
Public Function TimerOn(Interval As Integer)
   If Interval > 0 Then
      Timer1.Interval = Interval   ' Enables the timer.
   Else
      Timer1.Interval = 0         ' Disables the timer.
   End If
End Function

Open in new window

0
 

Author Comment

by:isnoend2001
ID: 39653525
Modified it to just pass the seconds:
Public Sub Chill(seconds As Integer)
  seconds = seconds * 1000
    Timer2.Interval = seconds '1000
    Timer2.Enabled = True
End Sub
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 39653534
That should work.

However, in complex program situations there could be a danger of confusing yourself when a variable called seconds is also used for milliseconds.
0
 

Author Comment

by:isnoend2001
ID: 39653544
thanks GrahamSkan i will keep that in mind
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question