Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMeasure elapsed time
Keywordselapsed time, time, timer function, seconds
CategoriesSoftware 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated