VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Format GetTickCount

by Alexandre Moro (5 Submissions)
Category: Math/Dates
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Format the GetTickCount() API to days, hours, minutes, seconds and miliseconds.
Useful to measure time elapsed between two points.

Inputs
A long containing the tick count value, and an optional parameter to use different format types. Ex.: Msgbox FormatCount(GetTickCount(),1)
Code Returns
A string containing the formated output.
API Declarations
Declare Function GetTickCount Lib "Kernel32" () As Long

Rate Format GetTickCount

Function FormatCount(Count As Long, Optional FormatType As Byte = 0) As String
   Dim Days As Integer, Hours As Long, Minutes As Long, Seconds As Long, Miliseconds As Long
   
   Miliseconds = Count Mod 1000
   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 & " dd, " & Hours & " h, " & _
      Minutes & " min, " & Seconds & " s, " & Miliseconds & _
      " ms"
    Case 1
      FormatCount = Days & " days, " & Hours & " hours, " & _
      Minutes & " minutes, " & Seconds & " seconds, " & Miliseconds & _
      " miliseconds"
    Case 2
      FormatCount = Days & ":" & Hours & ":" & _
      Minutes & ":" & Seconds & ":" & Miliseconds
   End Select
End Function

Download this snippet    Add to My Saved Code

Format GetTickCount Comments

No comments have been posted about Format GetTickCount. Why not be the first to post a comment about Format GetTickCount.

Post your comment

Subject:
Message:
0/1000 characters