Adding up into the chaos!
VB Code:
Public Type HourMinuteSecondMS Hours As Integer Mins As Byte Secs As Byte MS As Integer End Type Public Function GetHMSfromMS(ByVal Milliseconds As Long) As HourMinuteSecondMS GetHMSfromMS.Hours = CInt(Milliseconds \ 3600000) GetHMSfromMS.Mins = CByte((Milliseconds Mod 3600000) \ 60000) GetHMSfromMS.Secs = CByte((Milliseconds Mod 60000) \ 1000) GetHMSfromMS.MS = CInt(Milliseconds Mod 1000) End Function Public Function GetStrFromMS(ByVal Milliseconds As Long, Optional ByVal AlwaysFull As Boolean) As String Dim lngHours As Long, lngMins As Long, lngSecs As Long, lngMS As Long Dim blnHours As Long, blnMins As Long lngHours = Milliseconds \ 3600000 blnHours = (lngHours > 0) Or AlwaysFull lngMins = (Milliseconds Mod 3600000) \ 60000 blnMins = (lngMins > 0) Or blnHours lngSecs = (Milliseconds Mod 60000) \ 1000 lngMS = Milliseconds Mod 1000 If blnHours Then GetHMSfromMS = CStr(lngHours) & ":" & Format$(lngMins, "00") & ":" & _ Format$(lngSecs, "00") & "." & Format$(lngMS, "000") ElseIf blnMins Then GetHMSfromMS = Format$(lngMins, "00") & ":" & _ Format$(lngSecs, "00") & "." & Format$(lngMS, "000") Else GetHMSfromMS = Format$(lngSecs, "00") & "." & Format$(lngMS, "000") End If End Function
These are two different kinds of function. The other returns, at minimum, 00.000, but it automatically adds minutes or hours if necessary, so you end up with 00:00.000 or 0:00:00.000 formatted strings.
GetHMSfromMS instead returns a udt which contains all values splitted up nicely. This is useful if you want to make a custom digital display or something of that kind instead of using a label.




Reply With Quote