C McHale wrote: | |
|
Hi,
30 weekdays is 6 weeks so change the 14 to 42 at the bottom of the Do Loop for 6 whole weeks.
It won't matter if the day it starts on isn't a Monday, you will still get 30 weekdays of calculations.
You may want to show a progress bar to the end user to show something is happening if you are going to run calculations for up to 6 years.
Regards,
John
P.S. Please mark my post(s) As Answer if they have answered your questions.
PublicClass Form1
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Set a DATE.
Dim myDate AsDate = NowDim loopCount_NumberOfDays AsInteger = 0Dim outputString AsString = ""Do'To skip a specific holiday like Christmas Day and New Years day.>>If myDate.Month = 12 And myDate.Day = 25 ThenmyDate = myDate.AddDays(1)
loopCount_NumberOfDays += 1
outputString &=
"**** Christmas Day skipped!! ****"& vbCrLfEndIfIf myDate.Month = 1 And myDate.Day = 1 ThenmyDate = myDate.AddDays(1)
loopCount_NumberOfDays += 1
outputString &=
"**** New Years Day skipped!! ****"& vbCrLfEndIfSelectCase myDate.DayOfWeekCase DayOfWeek.Monday To DayOfWeek.Friday
outputString &= myDate.ToShortDateString & vbCrLf
'Do your calculations here.>>
'Add one to the current date.
myDate = myDate.AddDays(1)
loopCount_NumberOfDays += 1
Case DayOfWeek.Saturday'Add 1 day if it is a Saturday to show the Sunday message!!myDate = myDate.AddDays(1)
loopCount_NumberOfDays += 1
outputString &=
"**** Saturday skipped!! ****"& vbCrLfCase DayOfWeek.Sunday'Add 1 day if it is a Sunday.myDate = myDate.AddDays(1)
loopCount_NumberOfDays += 1
outputString &=
"**** Sunday skipped!! ****"& vbCrLfEndSelect'Loop for 42 days in total.LoopUntil loopCount_NumberOfDays = 42MessageBox.Show(outputString)
MessageBox.Show(
"Loop ran for "& loopCount_NumberOfDays.ToString & " days.")EndSubEnd
Class