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 varCurrentMinute >= 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(DaypartStart As String, DaypartEnd As String,
StartTime As String, EndTime As String) As Integer
Dim varStartTime, varEndTime As Variant
Dim varDaypartStart, varDaypartEnd As Variant
Dim varCurrentMinute As Variant
Dim intDaypartCount As Integer
varStartTime = TimeValue(StartTime)
varEndTime = TimeValue(EndTime)
varDaypartStart = TimeValue(DaypartStart)
varDaypartEnd = TimeValue(DaypartEnd)
intDaypartCount = 0
varCurrentMinute = varStartTime
Do While varCurrentMinute < varEndTime
If varCurrentMinute >= varDaypartStart _
And varCurrentMinute < varDaypartEnd Then
intDaypartCount = intDaypartCount + 1
End If
varCurrentMinute = varCurrentMinute + #12:01:00 AM#
Loop
If intDaypartCount > 0 Then
DaypartLength = intDaypartCount - 1
Else
DaypartLength = 0
End If
End Function