473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

anyone offer a better way?

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
Jun 28 '06 #1
3 1058
cj wrote:
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


You can break out of a loop:

For x As Integer = 0 To 10
If True Then
Exit For
End If
Next
Jun 28 '06 #2
How about something like this:

Dim ActionNeeded as Boolean = False
For x as Int32 = 0 to 6
ActionDateTime = Now.Date.AddDays(x).AddTicks(TimeValue(ActionTime) .Ticks)
Select Case ActionDateTime.DayOfWeek
Case DayOfWeek.Sunday
ActionNeeded = SunMenuItem.Checked
Case DayOfWeek.Monday
ActionNeeded = MonMenuItem.Checked
.....Etc
End Select
If ActionNeeded then
If ActionDateTime > Now then
Return ActionDateTime.ToShortDateString
EndIf
ActionNeeded = False
Next For
End Function
--
Terry
"cj" wrote:
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

Jun 28 '06 #3
cj
Quite true, it was too late inthe day to be thinking straight. I was
thinking about the other way. Forcing to jump to the next iteration.

Chris wrote:
cj wrote:
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


You can break out of a loop:

For x As Integer = 0 To 10
If True Then
Exit For
End If
Next

Jun 29 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: AF | last post by:
XOOPS - Anyone using it? What do you think of it? Thanks. Cheers to everyone, Al http://www.discountdrivingschool.com
3
by: Joannie Jae | last post by:
Need a script to allow users to post their social events, and having a devil of a time finding one. Some criteria: • Users can post their own event, without requiring any kind of registration. ...
6
by: Christian Seberino | last post by:
I am looking at the ELSE home page and trying to figure out if I should invest the time to learn about the ELSE minor mode for Emacs. Is there any programmer out there using ELSE that is getting...
4
by: Chuck Amadi | last post by:
Hi all Anyone know a good Pygresql Tutorial for Interfacing between Python & Postgresql . Cheers Chuck
102
by: RFox | last post by:
I date back to the early days of the web when HTML was limited but very managable, and have always maintained that hand-coding HTML gives you far better control and cleaner HTML markup than any...
14
by: vic | last post by:
My manager wants me to develop a search program, that would work like they have it at edorado.com. She made up her requirements after having compared how search works at different websites, like...
9
by: MLH | last post by:
Microsoft Office Professional Edition 2003 - Retail I've seen the above product advertised for $380. Are there enough developers world wide to make microsoft the following offer... If they...
31
by: Jim Hubbard | last post by:
I am downloading the REALbasic 5.5 demo and was just wondering if anyone else had tried it. I am tired of Microsoft constantly changing things and breaking backward compatibility ON PURPOSE. ...
10
by: 1010 | last post by:
Hey-I'm looking for people interested in programming an open-source OS based on unix. If any of you are interested, you can contact me at jjt@adio.info. *go and have a little fun*
169
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.