Just be advised that if you use the Sleep API call, you won't be able to process any events while it's sleeping. So you won't be able to repaint the screen, use any controls, or anything like that. If that isn't a problem, then Sleep is fine. If it is a problem, use a timer.
Function Delay%(sglDelayIntvl As Single)
'===========================================================
'
' Desc: This function delays for N 1/100's seconds.
' This is necessary because some screen flips free the
' Presentation Space a second before the next
' screen arrives.
'
' The Windows Sleep API is called to execute the
' delay. This API is recommended for 32 bit
' Visual Basic applications for "Waiting" in code.
'
' DoEvent statements are still issued so that: the
' "Busy" Form is updated by allowing the Timer
' control some time; and allow Windows to be more
' responsive to mouse events and painting, etc.
'
' Parms: sglDelayIntvl - number of seconds to wait before returning.
'
' Returns: 0 - Successful
' ELP_INVALID_WAIT_INTVL - Delay is not between 0 - 60 seconds
'
'===========================================================
Dim sglStartTime As Single
Dim sglEndTime As Single
Dim sglElapsedTime As Single
Dim lngdelay As Integer
If Not ((sglDelayIntvl > 0) And (sglDelayIntvl < OAS_MAX_WAIT_SECS)) Then
Delay% = ELP_INVALID_WAIT_INTVL
Exit Function
End If
' Convert delay time to the format (milliseconds) needed by the Sleep API
lngdelay = sglDelayIntvl * 1000
sglStartTime = Timer
' Wait for specified amount of time, but issue DoEvents at regular
' intervals, in order for forms to be updated and mouse events to
' be processed.
Do While (lngdelay > 0)
If (lngdelay > DELAY_INTERVAL) Then
Call Sleep(DELAY_INTERVAL)
lngdelay = lngdelay - DELAY_INTERVAL
Else
Call Sleep(lngdelay)
lngdelay = 0
End If
' Allow forms to be updated and mouse events to be processed
DoEvents
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.