Hello sir,
My program developed in VB6. I need to write a code to wait for few minutes , I tried it in timer control but it wont work .Cld u plz give a new solution.

Hello sir,
My program developed in VB6. I need to write a code to wait for few minutes , I tried it in timer control but it wont work .Cld u plz give a new solution.

The timer control does work, but it has a maximum wait time of about a minute (65535 milliseconds = 65+/- seconds).

For waiting longer than 1 minute, I use the sleep function. You need the following declare:
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

And, use the following call:
Sleep NumberOfMilliseconds

One think to keep in mind is that this will pause the entire application, so you may want to use a loop with a DoEvents statement along with the sleep call.

Unfortuantly, as CRMatthews pointed out Sleep will lock up the entire application but what they did not say is that if done for a long enough time, the application will become unresponsive in task manager and any kind of attempts by the user to interact with the program will only frustrate the user.

While a doevents loop with sleep is certainly one way to have your application pause for a few minutes, you idea of a timer "MAY" be a better solution. Lets say you want your program to pause for five minutes, then do something, and pause once again for five minutes...

Option Explicit

Dim PauseCount As Integer

Private Sub Form_Load()
Timer1.Interval = 60000 'one minute
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()

If PauseCount >= 5 Then
  PauseCount = 0
  'do some stuff
Else
  PauseCount = pausecnt + 1
End If

End Sub

Good Luck

I didn't include all of the logic needed in the loop - that would take away all the fun.

I usually use Sleep for a brief period (like 250ms) in a loop with DoEvents and a counter to get to the desired "time out" period.

So do I, but depending upon how responsive the program needs to be I may even go as low as 10ms, but OP was trying to use a timer for a delay...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.