GetTickCount Rolls Back To Zero? 
Author Message
 GetTickCount Rolls Back To Zero?

Since VB uses a signed long will gettickcount roll back to zero after it
reaches 2147483647? Will the following code work or does anyone see a more
efficient solution.

Public Function GetTicks() As Single

  Static LastTick As Long
  Static Base As Single

  Dim NowTick As Long
  NowTick = GetTickCount()
  If NowTick < LastTick Then Base = Base + 2147483647
  LastTick = NowTick
  GetTicks = Round(Base + CSng(NowTick) / 1000, 3)

End Function



Fri, 11 Apr 2003 03:00:00 GMT  
 GetTickCount Rolls Back To Zero?

Neal,

Quote:
> Since VB uses a signed long will gettickcount roll back to zero after it
> reaches 2147483647? Will the following code work or does anyone see a more
> efficient solution.

From the SDK:

The elapsed time is stored as a DWORD value. Therefore, the time will wrap
around to zero if the system is run continuously for 49.7 days.
If you need a higher resolution timer, use a multimedia timer or a
high-resolution timer.

Windows NT/2000: To obtain the time elapsed since the computer was started,
retrieve the System Up Time counter in the performance data in the registry
key HKEY_PERFORMANCE_DATA. The value returned is an 8-byte value. For more
information, see Performance Monitoring.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com



Fri, 11 Apr 2003 03:00:00 GMT  
 GetTickCount Rolls Back To Zero?

Hello!


Quote:
> Since VB uses a signed long will gettickcount roll back to zero after it
> reaches 2147483647? Will the following code work or does anyone see a more

No, It becames -2147483648.

Quote:
> efficient solution.

> Public Function GetTicks() As Single

>   Static LastTick As Long
>   Static Base As Single

>   Dim NowTick As Long
>   NowTick = GetTickCount()
>   If NowTick < LastTick Then Base = Base + 2147483647

 If NowTick < LastTick Then Base = Base + 4294967296

Quote:
>   LastTick = NowTick
>   GetTicks = Round(Base + CSng(NowTick) / 1000, 3)

> End Function

The precision of your function will decrease as value grows. I recommend you
to use Currency variables instead Single. It overflows after years.

Sergey Merzlikin



Fri, 11 Apr 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Rolling Averages - back to the drawing board

2. committing/rolling back all changes on form

3. Roll back transaction Error handling

4. Rolling back to vbx's afer upgrading to ocx's

5. RDO Problem when rolling back transaction - Function sequence error

6. Rolling back RDC changes

7. "rolling back" on AddNew

8. Implicit roll back when using server side cursor

9. Rolling back transactions

10. COM+ question: SetAbort not rolling back transaction?

11. MTS, VB and rolling back transactions

12. SetAbort does not roll back transaction

 

 
Powered by phpBB® Forum Software