I have a database and in some colsumsn i need to work with thousandths
of seconds. But in Time format I can´t adjust time in this format,
minimal are only seconds. Can somebody help me how to do it?
The easiest way is to store your time value as a Long integer representing the
total time as thousandths of a second and then use 2 functions to convert the
value from thousandths to formatted time and formatted time back to thousandths.
The following functions (air code) work for values < 1hour, if your times exceed
1 hour you will need to add another level to the functions. If your times are
less than 1 minute you will need to remove the top level of the functions.
From the debug window -
?fGetThousandths("15:35:985")
935985
?fGetFormatted(935985)
15:35:985
Hide your bound control containing the time value and use an unbound textbox to
manipulate the data.
Use the OnCurrent event to set the unbound textbox -
Me.MyUnboundControl = fGetFormatted(Me.MyDataControl)
Use the AfterUpdate event of the unbound control to update the hidden control -
Me.MyDataControl = fGetThousandths(Me.MyUnboundControl)
'==============================================
Function fGetThousandths(strTime As String) As Variant
Dim lngMinutes As Long
Dim lngSeconds As Long
Dim intThousandths As Integer
lngMinutes = Left(strTime, (InStr(1, strTime, ":") - 1))
strTime = Mid(strTime, InStr(1, strTime, ":") + 1, 99)
lngSeconds = Left(strTime, (InStr(1, strTime, ":") - 1))
strTime = Mid(strTime, InStr(1, strTime, ":") + 1, 99)
intThousandths = strTime
fGetThousandths = (lngMinutes * 60000) + (lngSeconds * 1000) + intThousandths
End Function
'==============================================
Function fGetFormatted(lngThousandths As Long) As String
Dim lngMinutes As Long
Dim lngSeconds As Long
Dim intThousandths As Integer
lngMinutes = lngThousandths \ 60000
lngThousandths = lngThousandths - (lngMinutes * 60000)
lngSeconds = lngThousandths \ 1000
intThousandths = lngThousandths - (lngSeconds * 1000)
intThousandths = intThousandths
fGetFormatted = lngMinutes & ":" & Format(lngSeconds, "00") & ":" &
Format(intThousandths, "000")
End Function
'==============================================
Wayne Gillespie
Gosford NSW Australia