Solved

vb6 - computer uptime

Posted on 2008-10-07
3
669 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
  • 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 500 total points
ID: 22667437
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 115
VB6 Compile Compatibility Issue 4 90
Microsoft Access combo box help 2 38
VB6 ListBox Question 4 34
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now