
Calculating time to the millisecond for Sleep() API
Use GetTickCounts, or timeGetTime. Then just pass the difference between the two to your sleep function.
Two important things however (that many seem to overlook). When performing the compare use a function (like the one below) to
account for VB signing and the OS wraps tick counts to zero:
function CompareTicks(byval tickstart as currency, byval tickend as currency)as long
' handle VB signing
if tickstart < 0 then
tickstart = tickstart + ccur(2 ^ 32)
end if
' handle VB signing or when OS wraps to zero
if tickend < 0 _
or tickend < tickstart then
tickend = tickend + ccur(2 ^ 32)
end if
compareticks = tickend - tickstart
end function
--
Monte Hansen
VB Yuk Yuk
http://KillerVB.com
<What the Yuk is a Yuk Yuk Anyway? Beats the Yuk outta Me!>
Does any body have a function or set of functions for calculating the
difference between two time periods so that the correct amount of time may
be passed to the sleep API. ie. Suppose I have a set of functions and
modules which execute non stop during business hours and I need to pause
execution after business hours are over. I need to calculate the
difference in current time and 0600 hours. The midnight boundary will
definately need be a factor in the calculation here. Everything needs to be
done in code as there are no forms or any other user interface to pause
execution.
I have the 0600 hours figured out as well as current time but I need to pass
the difference in time and pass it on to the sleep api call in milliseconds
so that execution will resume again at 0600. I have played with SetTimer
and all it does it crash on me. Even still I do not know how the callback
will do any better than a simple call to sleep(). A simple scheduling
algorithm may even help here. Thank you in advance as any help will be
greatly appreciated.