Link to home
Start Free TrialLog in
Avatar of XK8ER
XK8ERFlag for United States of America

asked on

vb6 - computer uptime

hello there,
I am having a problem here with this code and the computer uptime.. it works fine if the PC has been on for days but after months I get -21 something weird..
can someone tell me whats the issue? thanks
>>main
Option Explicit
 
Private Sub Timer1_Timer()
    UpLbl.Caption = FormatCount(GetTickCount, DaysHoursMinutesSecondsMilliseconds)
End Sub
 
 
>>module
Public Enum TimeFormatType
    DaysHoursMinutesSecondsMilliseconds = 0
    DaysHoursMinutesSeconds = 1
    DHMSMColonSeparated = 2
    DaysHoursMinutes = 3
End Enum
 
Public Function FormatCount(Count As Long, Optional FormatType As TimeFormatType = 0) As String
    Dim Days As Long, Hours As Long, Minutes As Long, Seconds As Long
    
    Count = Count \ 1000
    Days = Count \ (24& * 3600&)
    If Days > 0 Then Count = Count - (24& * 3600& * Days)
        Hours = Count \ 3600&
    If Hours > 0 Then Count = Count - (3600& * Hours)
    Minutes = Count \ 60
    Seconds = Count Mod 60
 
    Select Case FormatType
        Case 0
            FormatCount = Days & " days, " & Hours & " hours, " & Minutes & " minutes, " & Seconds & " seconds"
        
        Case 1
            FormatCount = Days & ":" & Hours & ":" & Minutes & ":" & Seconds
            
        Case 2
            FormatCount = Days & " days, " & Hours & " hours, " & Minutes & " minutes"
            
    End Select
End Function

Open in new window

Avatar of peetm
peetm
Flag of United Kingdom of Great Britain and Northern Ireland image

See

http://en.wikipedia.org/wiki/GetTickCount

There's also a solution there.
Avatar of Shanmuga Sundaram D
I believe that there is an issue if you have more than 25 days. You can store the from date and time in a variable and the finaldate and time in another variable and then find the up time.

see here

http://www.xtremevbtalk.com/archive/index.php/t-287257.html
ASKER CERTIFIED SOLUTION
Avatar of Shanmuga Sundaram D
Shanmuga Sundaram D
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial