Connecting Tech Pros Worldwide Forums | Help | Site Map

timeGetTime() vs Timer()

ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,219
#1   Mar 17 '07
If you're interested in measuring elapsed times in your Access Application, you're much better off using the timeGetTime() API Function instead of the Timer() VBA Function. There are 4 major reasons for this decision:
__1. timeGetTime() is more accurate. The Timer() Function measure time in 'seconds' since Midnight in a single-precision floating-point value, and is not terribly accurate. timeGetTime() returns the number of 'milliseconds' that have elapsed since Windows has started and is very accurate.
__2. timeGetTime() runs longer without 'rolling over'. Timer() rolls over every 24 hours. timeGetTime() keeps on ticking for up to 49 days before it resets the returned tick count to 0.
__3. Calling timeGetTime() is significantly faster than calling Timer().
__4. Calling timeGetTime() is no more complex than calling Timer(), once you've included the proper declaration as in:

Expand|Select|Wrap|Line Numbers
  1. Public Declare Function timeGetTime Lib "winmm.dll" () As Long 
A typical example of using timeGetTime would be:
Expand|Select|Wrap|Line Numbers
  1. Dim lngCounter As Long, dblSqr As Double
  2. Dim StartTime As Long, EndTime As Long
  3.  
  4. StartTime = timeGetTime()
  5.  
  6. For lngCounter = 1 To 20000000
  7.   dblSqr = Sqr(intCounter)
  8. Next
  9.  
  10. EndTime = timeGetTime()
  11. Debug.Print "It took " & (EndTime - StartTime) / 1000 & " seconds to process this loop" 
OUTPUT:
It took 1.316 seconds to process this loop



Reply


Similar Microsoft Access / VBA bytes