Hi guys - this twit's benused again!
I'm trying to write a function to return a string of comma delimited times in the format "hh:mm" representing 24 hours from a given start time with a specified interval. (Please dont ask why - life's too short!)
To add to the fun, I also want to include a start and end time inside which I don't want the values generating.
So I could generate for example every 20 minutes between 14:00 on one day to 14:00 on the next day, but not including times after 22:00 today and before 08:00 tomorrow.
The test harness and code follow:0
TEST HARNESS
CODE
The problem comes in the line
(btw - it's called datThisQH 'cos originally it was going to be used to generate Quarter Hour intervals).
Try running the code with a break on the line after the one giving the problem.
The values seem to be identical on a Watch (datThisQH and DatPauseAfter), but the code says datThisQH is greate than datPauseAfter!
Any kind soul got any bright ideas as to why?
Please???
I'm trying to write a function to return a string of comma delimited times in the format "hh:mm" representing 24 hours from a given start time with a specified interval. (Please dont ask why - life's too short!)
To add to the fun, I also want to include a start and end time inside which I don't want the values generating.
So I could generate for example every 20 minutes between 14:00 on one day to 14:00 on the next day, but not including times after 22:00 today and before 08:00 tomorrow.
The test harness and code follow:0
TEST HARNESS
Code:
Sub Times()
Dim intMins As Integer
Dim strResult As String
Dim strStart As String
Dim strPauseAfter As String
Dim strPauseUntil As String
strStart = "14:00"
strPauseAfter = "22:00"
strPauseUntil = "08:00"
intMins = 30
strResult = funIntervals(strStart, _
strPauseAfter, _
strPauseUntil, _
intMins)
MsgBox "Start Time " & strStart & vbCrLf & _
"Pause after " & strPauseAfter & " until " & strPauseUntil & vbCrLf & _
str
End Sub
Code:
Public Function funIntervals(strStart As String, _
strPauseAfter As String, _
strPauseUntil As String, _
Optional intMins = 15) As String
'*
'** Generate a string of comma delimited
'** time values in intMins minute intervals
'** between strStart time and strStart
'** time plus 1 day, but not including
'** times between strPauseAfter and
'** strPauseUntil.
'*
Dim booRecord As Boolean
Dim datPauseAfter As Date
Dim datStart As Date
Dim datStop As Date
Dim datThisQH As Date
Dim datTime As Date
Dim datPauseUntil As Date
Dim intPtr As Integer
Dim strResult As String
datStart = Date + TimeValue(CDate(strStart & ":00"))
datStop = DateAdd("d", 1, datStart)
datPauseAfter = Date + TimeValue(CDate(strPauseAfter & ":00"))
datPauseUntil = Date + TimeValue(CDate(strPauseUntil & ":00"))
datPauseUntil = DateAdd("d", 1, datPauseUntil)
datThisQH = datStart
strResult = ""
'*
'** Outer loop
'** First Start to last End.
'*
Do Until datThisQH > datStop
booRecord = True
If datThisQH > datPauseAfter Then
If datThisQH < datPauseUntil Then
booRecord = False
End If
End If
If booRecord Then
datTime = TimeValue(datThisQH)
strResult = strResult & _
"," & _
Left(CStr(datTime), 5)
End If
datThisQH = datThisQH + CDate("00:" & CStr(intMins) & ":00")
Loop
funIntervals = Right(strResult, Len(strResult) - 1)
End Function 'FunIntervals
Code:
If datThisQH > datPauseAfter Then
Try running the code with a break on the line after the one giving the problem.
The values seem to be identical on a Watch (datThisQH and DatPauseAfter), but the code says datThisQH is greate than datPauseAfter!
Any kind soul got any bright ideas as to why?
Please???