-
July 26th, 2002, 11:21 PM
#1
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.
Thanks.
-
July 26th, 2002, 11:57 PM
#2
sure is!! Try this
Public Sub Delay(HowLong As Date)
Dim TempTime As Date
TempTime = DateAdd("s", HowLong, Now)
While TempTime > Now
Wend
End Sub
All you do is send how long you want the delay to be ie:
delay 5
-
July 27th, 2002, 01:57 AM
#3
-
July 30th, 2002, 11:27 PM
#4
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Sleep 1000
End Sub
-
July 30th, 2002, 11:50 PM
#5
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, 02:07 AM
#6
Some additional:
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
Loop
End sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|