PDA

Click to See Complete Forum and Search --> : VB - A different timing approach


Daniel McCool
Dec 17th, 2003, 04:36 PM
I messed around with the Timer control to time my runtime operations, but couldn't quite get it to work efficiently. I'm sure there is some great Timer code out there, or some similar, but here was my solution to timing my code ....


tempTimeStart = Time 'Capture the computers time before the operations (12:34:56 AM)
tempTimeStart = Left$(tempTimeStart, Len(tempTimeStart) - 3) 'Cut off the AM part (12:34:56)
temp = Split(tempTimeStart, ":") 'Split the time into hours, minutes, and seconds (12,34,56)
tempTimeStart = (((temp(0) * 60) + temp(1)) * 60) + temp(2) 'Convert the hours into minutes, add on the minutes and convert them to seconds then add on the remaining seconds (((12*60)+34)*60)+56

DoEvents 'Operations ...

tempTimeEnd = Time 'The following code is same as above
tempTimeEnd = Left$(tempTimeEnd, Len(tempTimeEnd) - 3)
temp = Split(tempTimeEnd, ":")
tempTimeEnd = (((temp(0) * 60) + temp(1)) * 60) + temp(2)

tempTime = tempTimeEnd - tempTimeStart 'Find the difference in the times


.... basically caculating the time the code starts, and calculating the time it ends, then find the difference. Seems to work fine.

MartinLiss
Dec 17th, 2003, 07:25 PM
The time control is not very accurate. See the Time processes using GetTickCount link in my signature.

vbNeo
Jan 7th, 2004, 10:11 AM
That's some otherwise nice thinking dude, good thing you can work around problems, but in this case GetTickCount is just better =).

Cheers!