C
cj
I have menuitems that are checked or not checked for each day of the
week. If it's checked action will be taken on that day. There is also
the time of day that the action takes place to consider. This function
(which I haven't even tested yet) should find the next time action will
take place based on what days are checked and the time passed to it.
Actually I do this backward of what I'd like cause well I would break
out of the loop when I found the first time but that functionality isn't
available in VS2003 (though I could use a GOTO to approximate it).
Just curious what you might come up with. the long if statement is my
main objection to this method. But mostly just wondering what other
approaches someone might have.
Private Function NextAction(ByVal ActionTime As String) As String
Dim ActionDateTime As Date
NextAction = "Disabled"
For x As Int32 = 7 To 0 Step -1
ActionDateTime =
Now.Date.AddDays(x).AddTicks(TimeValue(ActionTime).Ticks)
If ActionDateTime.DayOfWeek = DayOfWeek.Sunday And
SunMenuItem.Checked Or _
ActionDateTime.DayOfWeek = DayOfWeek.Monday And
MonMenuItem.Checked Or _
ActionDateTime.DayOfWeek = DayOfWeek.Tuesday And
TueMenuItem.Checked Or _
ActionDateTime.DayOfWeek = DayOfWeek.Wednesday And
WedMenuItem.Checked Or _
ActionDateTime.DayOfWeek = DayOfWeek.Thursday And
ThuMenuItem.Checked Or _
ActionDateTime.DayOfWeek = DayOfWeek.Friday And
FriMenuItem.Checked Or _
ActionDateTime.DayOfWeek = DayOfWeek.Saturday And
SatMenuItem.Checked Then
If ActionDateTime > Now Then 'if x=0 (today) it might
be too late in the day
NextAction = ActionDateTime.ToShortDateString
End If
End If
Next
End Function
week. If it's checked action will be taken on that day. There is also
the time of day that the action takes place to consider. This function
(which I haven't even tested yet) should find the next time action will
take place based on what days are checked and the time passed to it.
Actually I do this backward of what I'd like cause well I would break
out of the loop when I found the first time but that functionality isn't
available in VS2003 (though I could use a GOTO to approximate it).
Just curious what you might come up with. the long if statement is my
main objection to this method. But mostly just wondering what other
approaches someone might have.
Private Function NextAction(ByVal ActionTime As String) As String
Dim ActionDateTime As Date
NextAction = "Disabled"
For x As Int32 = 7 To 0 Step -1
ActionDateTime =
Now.Date.AddDays(x).AddTicks(TimeValue(ActionTime).Ticks)
If ActionDateTime.DayOfWeek = DayOfWeek.Sunday And
SunMenuItem.Checked Or _
ActionDateTime.DayOfWeek = DayOfWeek.Monday And
MonMenuItem.Checked Or _
ActionDateTime.DayOfWeek = DayOfWeek.Tuesday And
TueMenuItem.Checked Or _
ActionDateTime.DayOfWeek = DayOfWeek.Wednesday And
WedMenuItem.Checked Or _
ActionDateTime.DayOfWeek = DayOfWeek.Thursday And
ThuMenuItem.Checked Or _
ActionDateTime.DayOfWeek = DayOfWeek.Friday And
FriMenuItem.Checked Or _
ActionDateTime.DayOfWeek = DayOfWeek.Saturday And
SatMenuItem.Checked Then
If ActionDateTime > Now Then 'if x=0 (today) it might
be too late in the day
NextAction = ActionDateTime.ToShortDateString
End If
End If
Next
End Function