468,107 Members | 1,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Share your developer knowledge by writing an article on Bytes.

timeGetTime() vs Timer()

8,799 Expert 8TB
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
  4. StartTime = timeGetTime()
  6. For lngCounter = 1 To 20000000
  7.   dblSqr = Sqr(intCounter)
  8. Next
  10. EndTime = timeGetTime()
  11. Debug.Print "It took " & (EndTime - StartTime) / 1000 & " seconds to process this loop" 
It took 1.316 seconds to process this loop
Mar 17 '07 #1
0 21617

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by marcus | last post: by
2 posts views Thread by DaveF | last post: by
2 posts views Thread by John David Thornton | last post: by
reply views Thread by Richard | last post: by
12 posts views Thread by Gina_Marano | last post: by
8 posts views Thread by =?Utf-8?B?RGF2ZSBCb29rZXI=?= | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.