?
Solved

vb6 - computer uptime

Posted on 2008-10-07
3
Medium Priority
?
694 Views
Last Modified: 2008-12-15
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

0
Comment
Question by:XK8ER
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Expert Comment

by:peetm
ID: 22666875
See

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

There's also a solution there.
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 22667435
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
0
 
LVL 17

Accepted Solution

by:
Shanmuga Sundaram earned 2000 total points
ID: 22667437
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question