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
 
 
 
 
 
TitleDisplay the ellapsed time after a long operation using DateDiff
KeywordsDateDiff, ellapsed time
CategoriesSoftware Engineering, Tips and Tricks
 
Use Date + Time to record the start and stop date and time. Use DateDiff to calculate the ellapsed time in days, hours, minutes, and seconds.
 
Private Sub cmdGo_Click()
Dim start_time As Date
Dim stop_time As Date
Dim i As Long
Dim max_value As Long

    lblDays.Caption = ""
    lblHours.Caption = ""
    lblMinutes.Caption = ""
    lblSeconds.Caption = ""

    max_value = CLng(txtCountTo.Text)
    Screen.MousePointer = vbHourglass
    DoEvents

    start_time = Date + Time

    For i = 1 To max_value
        ' Do nothing.
    Next i

    stop_time = Date + Time

    lblDays.Caption = Format$(DateDiff("d", start_time, _
        stop_time))
    lblHours.Caption = Format$(DateDiff("h", start_time, _
        stop_time))
    lblMinutes.Caption = Format$(DateDiff("m", start_time, _
        stop_time))
    lblSeconds.Caption = Format$(DateDiff("s", start_time, _
        stop_time))

    Screen.MousePointer = vbDefault
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated