Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Very accurate time

Status
Not open for further replies.

Horrid

Programmer
May 20, 1999
373
I need to be able to get time information accurate to 1/62 of a second. Does anyone know how to get millisecond or ticks since a start event?
 
The VB timer control offers resolution down to a millisecond. I don't have any information on it's accuracy.
 
The book I use reports that it only actually works once every 18.2 milliseconds or something like that. I need it once every 16.6 milliseconds, fast enough to measure 1 tick. If someone knows how to get a milliseconds since start from the timer I would appreciate it.<br>
Thanks anyway.
 
This is something from my collection of tips. Have<br>
never had to use it, but it might do what you are<br>
looking for. I CANNOT vouch for its integrity.<br>
<br>
HTH, Jim <br>
<br>
<br>
Replacement for Now() and Timer() <br>
The simple BetterNow() function, shown here, replaces the built-in Now() function. It's faster (10 microseconds vs. 180 microseconds on a Pentium 166MMX) and more accurate, potentially supplying one-millisecond resolution, instead of 1000 milliseconds. <br>
Because it's also faster and more accurate than Timer(), which clocks at 100 microseconds and provides 55 milliseconds resolution, it should also replace Timer, especially when Timer() is used to measure elapsed times. Besides, Timer() rolls over at midnight, and BetterNow() doesn't: <br>
<br>
#If Win16 Then<br>
Private Declare Function timeGetTime Lib _<br>
&quot;MMSYSTEM.DLL&quot; () As Long<br>
#Else<br>
Private Declare Function timeGetTime Lib &quot;winmm.dll&quot; _<br>
() As Long<br>
#End If<br>
<br>
Function BetterNow() As Date<br>
Static offset As Date<br>
Static uptimeMsOld As Long<br>
Dim uptimeMsNew As Long<br>
Const oneSecond = 1 / (24# * 60 * 60)<br>
Const oneMs = 1 / (24# * 60 * 60 * 1000)<br>
uptimeMsNew = timeGetTime()<br>
' check to see if it is first time function called or<br>
' if timeGetTime rolled over (happens every 47 days)<br>
If offset = 0 Or uptimeMsNew &lt; uptimeMsOld Then<br>
offset = Date - uptimeMsNew * oneMs + CDbl(Timer) * _<br>
oneSecond<br>
uptimeMsOld = uptimeMsNew<br>
End If<br>
BetterNow = uptimeMsNew * oneMs + offset<br>
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top