Click to See Complete Forum and Search --> : Time elapsed
Alex
November 6th, 1998, 05:48 PM
Anyone know how I can get the time elapsed of a application? I wanna know how long something took to run. I tried:
Dim time1, time2, TimeElapsed
time1 = time$
'Application runs here
time2 = time$
TimeElapsed = (time2-time1)
Any idea why its not working, and now I can get it to work? thanks ;)
Gordito
November 7th, 1998, 06:57 AM
Use the GetTickCount API ... the declarations you need can be found in the API Viewer. It can be used like this.
Dim time1%,time2%,elapsed%
time1 = GetTickCount()
'whatever process you are timing
time2 = GetTickCount()
elasped = time2-time1
'elapsed will be the number of milliseconds that have elapsed
'GetTickCount rolls over every 49 days of continuous system operation so if 'time1 is greater than time2, you have to make the necessary adjustment
Gordito
James Grant
November 27th, 1998, 11:36 AM
Alex:
You have several issues with this code:
1. Always type your variables (Dim time1 As Date), otherwise they are variants (really slow).
2. Putting a $ returns a string, your untyped time1 will now hold the string.
3. You then try subtracting strings
Try this:
Dim x As Date
Dim y As Date
x = Now
'' App runs here
y = Now
Call MsgBox(DateDiff("s", x, y) & " seconds have passed.", vbInformation)
Tested in VB5.
-Jim
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.