Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleSee how long Windows has been running
KeywordsWindows, time, run time
CategoriesWindows, API
 
The GetTickCount API function returns the time the system has been running in milliseconds. Convert that result into days, hours, minutes, and seconds.
 
Private Sub tmrCheckTime_Timer()
Const MS_PER_SEC As Long = 1000
Const MS_PER_MIN = MS_PER_SEC * 60
Const MS_PER_HR = MS_PER_MIN * 60
Const MS_PER_DAY = MS_PER_HR * 24

Dim ms As Long
Dim secs As Long
Dim mins As Long
Dim hrs As Long
Dim days As Long

    ms = GetTickCount()
    days = ms \ MS_PER_DAY
    ms = ms - days * MS_PER_DAY
    hrs = ms \ MS_PER_HR
    ms = ms - hrs * MS_PER_HR
    mins = ms \ MS_PER_MIN
    ms = ms - mins * MS_PER_MIN
    secs = ms \ MS_PER_SEC
    ms = ms - secs * MS_PER_SEC

    lblDays.Caption = Format$(days) & " days"
    lblHrs.Caption = Format$(hrs) & " hours"
    lblMins.Caption = Format$(mins) & " minutes"
    lblSecs.Caption = Format$(secs) & " seconds"
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated