Advice

I am a little caught about by my own functionality. I have a schedule object where one of the options is to set a reminder for every week, in addition I also allow them to set it to run on specifc days of the week.

So for example they could have a job run every week on Mon, Tues and Fri.

The problem I have is this

If the next run date is set to the 12 (this week), I am assuming I should set the next due date to the 13th, then the 16th and then the 19th and so on.

Is the easier option to check what day it is then add on so many days?
Is there an easy way of doing this?

Any help would be appreciated

rocky050371Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
you have to create a property getter/setter:

    Private _myprop As String
    Public Property MyProp() As String
        Get
            Return _myprop
        End Get
        Set(ByVal value As String)
            _myprop = value
        End Set
    End Property
0
CodeCruiserCommented:
0
CodeCruiserCommented:
You can check the DayOfWeek against each date and keep adding 1 day to it so that it becomes that day.

For example

Dim dt as DateTime = Now

If dt.DayOfWeek <> DayOfWeek.Monday Then
   While dt.DayOfWeek <> DayofWeek.Monday
          dt = dt.AddDays(1)
   End while
End If
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

rocky050371Author Commented:
I have this so far, can anyone think of a better way


  If schedule.SchedFrequencyIntervalException <> 0 Then
                                            Select Case schedule.SchedNextRun.DayOfWeek
                                                Case DayOfWeek.Monday
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Tuesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1)
                                                    End If
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Wednesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(2)
                                                    End If
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Thursday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1)
                                                    End If
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Friday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(2)
                                                    End If
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Saturday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1)
                                                    End If
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Sunday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(2)
                                                    End If
                                                Case DayOfWeek.Tuesday
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Wednesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1)
                                                    End If


                                            End Select






                                        Else
                                            schedule.SchedNextRun = schedule.SchedNextRun.AddDays(schedule.SchedFrequencyInterval * 7)
                                        End If
0
rocky050371Author Commented:
The code has not been validated and needs a couple more branches, it just seems a bit code intensive
0
rocky050371Author Commented:
Right this is closer to what it would look like

 If schedule.SchedFrequencyIntervalException <> 0 Then
                                            Select Case schedule.SchedNextRun.DayOfWeek
                                                Case DayOfWeek.Monday
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Tuesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Wednesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(2)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Thursday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(3)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Friday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(4)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Saturday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(5)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Sunday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(6)
                                                    Else
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(schedule.SchedFrequencyInterval * 7)
                                                    End If
                                                Case DayOfWeek.Tuesday
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Wednesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1)
                                                    End If

                                            End Select

                                        Else
                                            schedule.SchedNextRun = schedule.SchedNextRun.AddDays(schedule.SchedFrequencyInterval * 7)
                                        End If
0
rocky050371Author Commented:
Right ignore the rest :-), any advice on this

Case FrequencyType.Weeks

                                        iDayWeekConstant = schedule.SchedFrequencyInterval * 7

                                        If schedule.SchedFrequencyIntervalException <> 0 Then

                                            Select Case schedule.SchedNextRun.DayOfWeek
                                                Case DayOfWeek.Monday
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Tuesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Wednesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(2)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Thursday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(3)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Friday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(4)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Saturday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(5)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Sunday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(6)
                                                    Else
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(iDayWeekConstant)
                                                    End If
                                                Case DayOfWeek.Tuesday
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Wednesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Thursday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(2)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Friday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(3)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Saturday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(4)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Sunday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(5)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Monday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(6 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    Else
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(iDayWeekConstant)
                                                    End If
                                                Case DayOfWeek.Wednesday
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Thursday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Friday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(2)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Saturday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(3)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Sunday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(4)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Monday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(5 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Tuesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(6 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    Else
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(iDayWeekConstant)
                                                    End If
                                                Case DayOfWeek.Thursday
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Friday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Saturday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(2)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Sunday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(3)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Monday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(4 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Tuesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(5 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Wednesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(6 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    Else
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(iDayWeekConstant)
                                                    End If
                                                Case DayOfWeek.Friday
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Saturday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Sunday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(2)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Monday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(3 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Tuesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(4 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Wednesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(5 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Thursday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(6 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    Else
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(iDayWeekConstant)
                                                    End If
                                                Case DayOfWeek.Saturday
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Sunday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1)
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Monday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(2 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Tuesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(3 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Wednesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(4 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Thursday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(5 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Friday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(6 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    Else
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(iDayWeekConstant)
                                                    End If
                                                Case DayOfWeek.Sunday
                                                    If CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Monday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(1 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Tuesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(2 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Wednesday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(3 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Thursday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(4 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Friday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(5 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    ElseIf CheckDayFlag(CType(schedule.SchedFrequencyIntervalException, DaysOfTheWeek), DaysOfTheWeek.Saturday) Then
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(6 + If(iDayWeekConstant > 7, iDayWeekConstant - 7, 0))
                                                    Else
                                                        schedule.SchedNextRun = schedule.SchedNextRun.AddDays(iDayWeekConstant)
                                                    End If
                                            End Select
                                        Else
                                            schedule.SchedNextRun = schedule.SchedNextRun.AddDays(iDayWeekConstant)
                                        End If

Open in new window

0
CodeCruiserCommented:
You are checking the day of the week of schedule and then based on today's day of week, you are adding the days to the schedule? So if schedule is to run on thursday and today is monday, you are adding 3?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rocky050371Author Commented:
Yes, it was just to see if there is a better way
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.