What should be a very simple function is going terribly wrong, and I
don't know why. StartTime and EndTime are table values (formatted like
"01:00A" or "02:00P"); DaypartStart and DaypartEnd are string values I
specify when calling the function (initially tried passing time values
& the same problem occurs); In the If statement, I can compare the
exact same time values, and the varCurrentMinut e >= varDaypartStart
equality will not work; Two time values will not test to equality,
even though they show as the same time? How do I fix this?
Function DaypartLength(D aypartStart As String, DaypartEnd As String,
StartTime As String, EndTime As String) As Integer
Dim varStartTime, varEndTime As Variant
Dim varDaypartStart , varDaypartEnd As Variant
Dim varCurrentMinut e As Variant
Dim intDaypartCount As Integer
varStartTime = TimeValue(Start Time)
varEndTime = TimeValue(EndTi me)
varDaypartStart = TimeValue(Daypa rtStart)
varDaypartEnd = TimeValue(Daypa rtEnd)
intDaypartCount = 0
varCurrentMinut e = varStartTime
Do While varCurrentMinut e < varEndTime
If varCurrentMinut e >= varDaypartStart _
And varCurrentMinut e < varDaypartEnd Then
intDaypartCount = intDaypartCount + 1
End If
varCurrentMinut e = varCurrentMinut e + #12:01:00 AM#
Loop
If intDaypartCount > 0 Then
DaypartLength = intDaypartCount - 1
Else
DaypartLength = 0
End If
End Function