|
|
Title | Measure elapsed time |
Keywords | elapsed time, time, timer function, seconds |
Categories | Software Engineering, Tips and Tricks |
|
|
Declare two Double variables for the start and stop times. Set their values using the Timer function, which returns the number of seconds that have passed since midnight (yes, that means this doesn't work if the time interval spans midnight). Subtract the values and use Format to display the result.
|
|
Private Sub cmdStart_Click()
Static start_time As Double
Dim stop_time As Double
Dim elapsed_time As Double
If cmdStart.Caption = "Start" Then
lblElapsed.Caption = ""
start_time = Timer
cmdStart.Caption = "Stop"
Else
stop_time = Timer
elapsed_time = stop_time - start_time
lblElapsed.Caption = Format$(elapsed_time, _
"0.000000")
cmdStart.Caption = "Start"
End If
End Sub
|
|
|
|
|
|