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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timer calculation bug

Status
Not open for further replies.

PoppapumpJ

Programmer
Dec 17, 2001
86
US
Hi,

I am attempting to make a record of how long it takes to run a function. I am using the Timer function to see time down to the millisecond.

However the problem I am seeing is that sometimes I get a negative number.

Here is an example:

Code:
GenericTimer = Timer
objMyObject.myFunction
msgBox (Timer - GenericTimer)

The problem I a seeing is that sometimes the number comes back negative.

Does anyone know of any bugs associated with using the Timer function in this manner?

Thanks,
 
Since the Timer Function "Returns a Single representing the number of seconds since midnight" are you perhaps running your program overnight?


Perhaps try using the GetTickCount Function

Code:
Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long

Code:
Dim GenericTimer as Long
GenericTimer = GetTickCount()
objMyObject.myFunction
MsgBox (GetTickCount() - GenericTimer)
 
>down to the millisecond

Well ... you'll be disappointed ... best you'll typically get with the commonly available timing calls (and dependant on the OS) is about 10 milliseconds
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top