Calculating time to the millisecond for Sleep() API 
Author Message
 Calculating time to the millisecond for Sleep() API

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.



Thu, 27 Mar 2003 03:00:00 GMT  
 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.



Thu, 27 Mar 2003 03:00:00 GMT  
 Calculating time to the millisecond for Sleep() API

Hi,

You can use the timeGetTime API.

--
Richard Grier (Microsoft Visual Basic MVP)
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO  80228
303-986-2179 (voice)
303-986-3143 (fax)
Author of Visual Basic Programmer's Guide to Serial Communications, 2nd
Edition ISBN 1-890422-25-8 (355 pages).
For information look on my homepage at http://www.hardandsoftware.net.
Use the Books link to order.  For faster service contact the publisher at
http://www.mabry.com/vbpgser.



Fri, 28 Mar 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Can Win95 API measure sub-millisecond TIME intervals?

2. Sleep API is using up 60% CPU time in the DLL

3. Sleep() api timing???

4. calculate dates calculate time

5. Calculating elapsed time and adding time values

6. Millisecond timing in Excel VBA

7. PowerBasic : measure of elapsed time in milliseconds

8. Millisecond timing - request.

9. VB Time in Milliseconds

10. Dividing time into milliseconds

11. Showing time in milliseconds?

12. system date and time to the millisecond?

 

 
Powered by phpBB® Forum Software