time delay

I´ve found a really nice tip for stop the code for x seconds.
It goes like this:

Sub Pause(ByVal nSecond As Single)
Dim t0 As Single
Dim dummy As Integer
       
        t0 = Timer
       
        Do While Timer - t0 < nSecond
               
                dummy = DoEvents()
               
                ' If we cross midnight, back up one day
                If Timer < t0 Then
                        t0 = t0 - 24 * 60 * 60 ' or t0 = t0 - 86400

                End If
        Loop

End Sub

'-----

Private Sub Command1_Click()
Dim x As Integer
x = seconds.Text

Call Pause(x)  ' delay for x seconds
Label1.Caption = "ok"
 
End Sub

'-----

The problem I had is: How can I use this if I want to stop the code for less than a second?

But it really is a nice tip!!!

Thx for your help guys!

alexbeatyAsked:
Who is Participating?
 
stewfidgeonConnect With a Mentor Commented:
I dont think you can. You can however use the sleep API to pause execution for milliseconds.

An example of this can be found at :
http://www.zarr.com/vb/download/topdownloads.html
called sleepy eyes.


Hope this helps.
0
 
stewfidgeonCommented:
Alexbeaty,

Is my answer OK? Can you either accept it or reject it please.

If you want a simpler example of sleep API, follow this link:

http://www.programmerz.com/vb/code/084.htm

0
 
stewfidgeonCommented:
Alexbeaty:

I took the time to answer your question, I think it's fair that you should spend the time to grade my answer.

Thanks,
Stew.
0
All Courses

From novice to tech pro — start learning today.