July 27th, 2002, 12:21 AM
Time Delay in VB
is there a function to make a time delay in vb? something like sleep(1000)?
I tried using the timer, but it doesnt make the other processes stop and wait.
July 27th, 2002, 12:57 AM
sure is!! Try this
Public Sub Delay(HowLong As Date)
Dim TempTime As Date
TempTime = DateAdd("s", HowLong, Now)
While TempTime > Now
All you do is send how long you want the delay to be ie:
July 27th, 2002, 02:57 AM
July 31st, 2002, 12:27 AM
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
July 31st, 2002, 12:50 AM
Just to add some information to it. There is one limitation with the solutions given to this problem. The "sleep API" or the "while wend" method will put the application in non responding mode. i.e. if the requirement is to wait for around 30 seconds, then by using either of these methods,application will not accept any other event till the control comes out of sleep or while loop. it may affect the functionality of the application to great extent. So the user should be very careful while using these methods.
July 31st, 2002, 03:07 AM
To avoid your application seem to be dead, you can divide the delay period into a number of small intervals and then use the loop with DoEvents inside. It's something like this:
Const Interval = 200 ' 0.2 s
Private Sub delay(delayPeriod as Long)
Dim delay as long
delay = 0
Do while (delay < delayPeriod)
delay = delay + Interval
DoEvents ' Process other events
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!