Below is code I have retrieved from peterssoftware.com.
Custom Time Funciton.mdb - I got an example of how to use this in query:
Select ctf_Construct(ctf_Divide(ctf_Parse(MyTimeString), 3)) From MyTable;
But I can't get it to work. I have been messing with:
FltHrsDay: ctf_Construct("SELECT(ctf_Divide(ctf_Parse([TotHrsDay]),([TotACDays]))) FROM FleetUtilization")
But can't get it to work either. I get a data mismatch message. Any fixes???
Thanks in advance - jw
Function ctf_Construct(ct As cTime_struct) As String
'* convert a ctime_struct variable into a time string with subseconds
Dim s As String
Dim sSubSecondFormat As String
Dim lng As Long
lng = CLng(SubSecondsPerSecond) - 1
Select Case Len(CStr(lng))
Case 1
sSubSecondFormat = "0"
Case 3
sSubSecondFormat = "000"
Case 4
sSubSecondFormat = "0000"
Case 5
sSubSecondFormat = "00000"
Case 6
sSubSecondFormat = "000000"
Case Else
sSubSecondFormat = "00"
End Select
s = Format(ct.hour, "00") & ":" & Format(ct.minute, "00") & ":" & _
Format(ct.second, "00") & "," & Format(ct.subsecond, sSubSecondFormat)
ctf_Construct = s
End Function
Function ctf_Divide(ct As cTime_struct, intOperand As Integer) As cTime_struct
'* divide "ctime" by an integer
Dim minusct As cTime_struct
Dim ctres As cTime_struct
Dim inttemp As Integer
Dim remainder As Integer
'MsgBox ctime & " / " & intOperand
If intOperand <> 0 Then
ctres.hour = ct.hour \ intOperand
inttemp = (MinutesPerHour * (ct.hour Mod intOperand) + ct.minute)
ctres.minute = inttemp \ intOperand
inttemp = (SecondsPerMinute * (inttemp Mod intOperand) + ct.second)
ctres.second = inttemp \ intOperand
inttemp = (SubSecondsPerSecond * (inttemp Mod intOperand) + ct.subsecond)
ctres.subsecond = inttemp \ intOperand
Else
ctres.hour = 0
ctres.minute = 0
ctres.second = 0
ctres.subsecond = 0
End If
'MsgBox "result: " & ctres.hour & ":" & ctres.minute & ":" & ctres.second & "," & ctres.subsecond
'MsgBox ctf_Construct(ctsum)
ctf_Divide = ctres
End Function
Function ctf_Parse(ctime As String) As cTime_struct
'* break down the ctime string into an ctime structure
Dim ct As cTime_struct
Dim pos As Integer
Dim startpos As Integer
Dim SearchChar As String
startpos = 1
SearchChar = ":"
pos = InStr(ctime, SearchChar)
ct.hour = Val(Mid(ctime, startpos, pos - startpos))
'MsgBox ct.hour & " " & ct.minute & " " & ct.second & " " & ct.frame
startpos = pos + 1
pos = InStr(startpos, ctime, SearchChar)
ct.minute = Val(Mid(ctime, startpos, pos - startpos))
'MsgBox ct.hour & " " & ct.minute & " " & ct.second & " " & ct.frame
startpos = pos + 1
SearchChar = ","
pos = InStr(startpos, ctime, SearchChar)
ct.second = Val(Mid(ctime, startpos, pos - startpos))
'MsgBox ct.hour & " " & ct.minute & " " & ct.second & " " & ct.frame
startpos = pos + 1
ct.subsecond = Val(Mid(ctime, startpos, Len(ctime) + 1 - startpos))
'MsgBox ct.hour & " " & ct.minute & " " & ct.second & " " & ct.frame
ctf_Parse = ct
End Function
Custom Time Funciton.mdb - I got an example of how to use this in query:
Select ctf_Construct(ctf_Divide(ctf_Parse(MyTimeString), 3)) From MyTable;
But I can't get it to work. I have been messing with:
FltHrsDay: ctf_Construct("SELECT(ctf_Divide(ctf_Parse([TotHrsDay]),([TotACDays]))) FROM FleetUtilization")
But can't get it to work either. I get a data mismatch message. Any fixes???
Thanks in advance - jw
Function ctf_Construct(ct As cTime_struct) As String
'* convert a ctime_struct variable into a time string with subseconds
Dim s As String
Dim sSubSecondFormat As String
Dim lng As Long
lng = CLng(SubSecondsPerSecond) - 1
Select Case Len(CStr(lng))
Case 1
sSubSecondFormat = "0"
Case 3
sSubSecondFormat = "000"
Case 4
sSubSecondFormat = "0000"
Case 5
sSubSecondFormat = "00000"
Case 6
sSubSecondFormat = "000000"
Case Else
sSubSecondFormat = "00"
End Select
s = Format(ct.hour, "00") & ":" & Format(ct.minute, "00") & ":" & _
Format(ct.second, "00") & "," & Format(ct.subsecond, sSubSecondFormat)
ctf_Construct = s
End Function
Function ctf_Divide(ct As cTime_struct, intOperand As Integer) As cTime_struct
'* divide "ctime" by an integer
Dim minusct As cTime_struct
Dim ctres As cTime_struct
Dim inttemp As Integer
Dim remainder As Integer
'MsgBox ctime & " / " & intOperand
If intOperand <> 0 Then
ctres.hour = ct.hour \ intOperand
inttemp = (MinutesPerHour * (ct.hour Mod intOperand) + ct.minute)
ctres.minute = inttemp \ intOperand
inttemp = (SecondsPerMinute * (inttemp Mod intOperand) + ct.second)
ctres.second = inttemp \ intOperand
inttemp = (SubSecondsPerSecond * (inttemp Mod intOperand) + ct.subsecond)
ctres.subsecond = inttemp \ intOperand
Else
ctres.hour = 0
ctres.minute = 0
ctres.second = 0
ctres.subsecond = 0
End If
'MsgBox "result: " & ctres.hour & ":" & ctres.minute & ":" & ctres.second & "," & ctres.subsecond
'MsgBox ctf_Construct(ctsum)
ctf_Divide = ctres
End Function
Function ctf_Parse(ctime As String) As cTime_struct
'* break down the ctime string into an ctime structure
Dim ct As cTime_struct
Dim pos As Integer
Dim startpos As Integer
Dim SearchChar As String
startpos = 1
SearchChar = ":"
pos = InStr(ctime, SearchChar)
ct.hour = Val(Mid(ctime, startpos, pos - startpos))
'MsgBox ct.hour & " " & ct.minute & " " & ct.second & " " & ct.frame
startpos = pos + 1
pos = InStr(startpos, ctime, SearchChar)
ct.minute = Val(Mid(ctime, startpos, pos - startpos))
'MsgBox ct.hour & " " & ct.minute & " " & ct.second & " " & ct.frame
startpos = pos + 1
SearchChar = ","
pos = InStr(startpos, ctime, SearchChar)
ct.second = Val(Mid(ctime, startpos, pos - startpos))
'MsgBox ct.hour & " " & ct.minute & " " & ct.second & " " & ct.frame
startpos = pos + 1
ct.subsecond = Val(Mid(ctime, startpos, Len(ctime) + 1 - startpos))
'MsgBox ct.hour & " " & ct.minute & " " & ct.second & " " & ct.frame
ctf_Parse = ct
End Function