Results 1 to 4 of 4

Thread: How can you get current uptime using GetTickCount?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195

    How can you get current uptime using GetTickCount?

    Heres my current code:
    VB Code:
    1. MilliSeconds = GetTickCount
    2.     Days = MilliSeconds / 86400000
    3.     MilliSeconds = MilliSeconds Mod 86400000
    4.     Hours = MilliSeconds / 3600000
    5.     MilliSeconds = MilliSeconds Mod 3600000
    6.     Minutes = MilliSeconds / 60000
    7.     MilliSeconds = MilliSeconds Mod 60000
    8.     Seconds = MilliSeconds / 1000
    but this has major issues with rounding (IE 1hr 30 mins is displayed as 2 hr 30 min)

    anyone know of anything else?

  2. #2
    Hyperactive Member ZeroCool's Avatar
    Join Date
    Feb 2002
    Location
    In front of my computer
    Posts
    423
    What Have You Declared MilliSeconds, Days, Hours, Seconds as?
    Visual Baisc 6 (SP5)
    Windows Xp

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195
    Dim MilliSeconds As Long, Days As Integer
    Dim Hours As Integer, Minutes As Integer, Seconds As Integer

    should they all be long?

  4. #4
    Fanatic Member Slaine's Avatar
    Join Date
    Jul 2002
    Posts
    641
    The following seems to work for me.

    VB Code:
    1. Dim Days, Hours, Minutes, Seconds As Long
    2.    
    3.     Dim ret As Long
    4.    
    5.     'Get the tickcount
    6.     ret = GetTickCount&
    7.    
    8.     Days = ret \ 86400000
    9.     Hours = (ret - (Days * 86400000)) \ 3600000
    10.     Minutes = (ret - (Days * 86400000) - (Hours * 3600000)) \ 60000
    11.     Seconds = (ret - (Days * 86400000) - (Hours * 3600000) - (Minutes * 60000)) \ 1000
    12.    
    13.     MsgBox Days & " Days, " & Hours & " Hours, " & Minutes & " Minutes, " & Seconds & " Seconds."
    Martin J Wallace (Slaine)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width