VBS Holiday Countdown
Do you wonder what the next holiday is? Do you wonder when the next holiday is? Wouldn’t it be nice to have a holiday tracker? Something that will tell you the next holiday, how many days until that holiday as well the remaining holidays of the year.
What do we know about US holidays? Well, federal holidays have been passed by Congress and are set to a specific date i.e. the 4th of July; or a specific Monday making a long weekend. i.e. the last Monday of May; or a specific Thursday i.e. the 4th Thursday of November. There are 10 federal holidays in the US. Where government institutions as well as banks, post offices and schools are closed. Any non federal employees who work on one of those days is entitled to holiday pay in addition to their regular pay. Those who do not work can enjoy a day off, maybe some good food, good company, fun activities, etc, etc, etc.
So I ask who wouldn’t want to easily keep track of holidays? Well you can once you create this VBS Holiday Countdown. Now you can be kept informed of when and what the next holiday is, how many days until the next holiday, as well as the remaining holidays of this year. In fact I designed this VBS Holiday Countdown to be a perpetual holiday calendar. The holiday dates will reflect the current year. The holidays where the date stays the same e.g. New Year's Day, July 4th, Christmas Day and New Year's Eve those will always be on those dates. But the holidays where they are on the 3rd Monday of Jan, the 1st Monday of September and the 4th Thursday of November, those dates will change because of the Gregorian calendar. This VBS Holiday Countdown will account for those different holiday dates.
This VBS Holiday Countdown keeps track of the 10 federal holidays and I added Valentine's Day because Love is wonderful and New Year's Eve because that is the day the celebration begins to end the year and bring the new year. The image examples show what the VBS Holiday Countdown will look like at 4 different times of the year.
Items Covered
1) A Message box,
A Message box is a way to display a message and allow you to answer Yes, No, Cancel, Retry or Ignore.
2) Select Case Statements,
Select Case Statements tells the code what to do when a condition is met.
3) Date Function,
Functions are a predefined command to manipulate a value.
* DateSerial – DateSerial( Year , Month , Day ); returns a date given a year, month, and day. Year can either be a year i.e. “2013” or “Date” which will give you the current year. Month can be either a number from 1 to 12 or “Date” which will give you the current month. Day can be either a number from 1 to 31 or “Date” which will give you the current day.
* WeekDay – ( Date, [firstdayofweek]* ); returns a number representing the day of the week (a number from 1 to 7). *firstdayofweek is optional, it is used to tell what day is the first day of the week, default is Sunday if left blank.
* DateDiff – DateDiff( Interval* , Date1 , Date2 ); returns the difference between two dates, based on the interval specified. *Interval is the measurement of time to use to calculate the difference between date1 and date2. The common intervals for dates are “yyyy” for Year, “m” for Month and “d” for day.
Date Functions can be combined to further manipulate the date value. See if you can find the different ways I used the Date Functions.
4) IF THEN ELSEIF Statements
IF THEN ELSEIF Statements executes code when the condition is met or True.
5) Array and
An Array is a fixed list of variables with an index. The array will allow the code to pick only the variables that it needs.
6) How to Comment out notes in the code.
Comment out notes is important. It allows anyone to know what is going on at that point in the code. The code will not run when the line is preceded by ' an Apostrophe.
Skill Level
Easy – if you copy and paste.
Medium – if you want to change the code.
Time to Complete
5 – 10 minutes, more if you make changes.
Compare 2/7/2013 and 2/16/2013
The Code
1) Open the Notepad application:
Click Start => click Programs => click Accessories => click Notepad
Or
Click Start => Click Run => Type Notepad in the Run input box then Click OK.
2) Copy the code below the Apostrophe and Asterisks line then Paste it into Notepad.
' *********************************************
Dim Notice
Notice = "Remaining Holidays of this Year " & Year(Date)
If Month(date)= 1 and Date < DateSerial(Year(Date),1,22) - Weekday(DateSerial(Year(Date),1,22),3) then
Holiday = 1
ElseIf Month(date)= 1 and Date > DateSerial(Year(Date),1,22) - Weekday(DateSerial(Year(Date),1,22),3) then
Holiday = 2
ElseIf Month(date)= 2 and Date < DateSerial(Year(Date),2,14) then
Holiday = 2
ElseIf Month(date)= 2 and Date < DateSerial(Year(Date),3,1) - Weekday(DateSerial(Year(Date),3,1),3) - 7 then
Holiday = 3
ElseIf Month(date)=2 then
Holiday = 4
ElseIf Month(date)=3 then
Holiday = 4
ElseIf Month(date)=4 then
Holiday = 4
ElseIf Month(date)=5 and date < DateSerial(Year(Date),6,1) - Weekday(DateSerial(Year(Date),6,1),3) then
Holiday = 4
ElseIf Month(date)=5 and date > DateSerial(Year(Date),6,1) - Weekday(DateSerial(Year(Date),6,1),3) then
Holiday = 5
ElseIf Month(date)=6 then
Holiday = 5
ElseIf Month(date)=7 and date < DateSerial(Year(Date),7,4) then
Holiday = 5
ElseIf Month(date)=7 and date > DateSerial(Year(Date),7,4) then
Holiday = 6
ElseIf Month(date)=8 then
Holiday = 6
ElseIf Month(date)=9 and date < DateSerial(Year(Date),9,7) - Weekday(DateSerial(Year(Date),9,7),3) then
Holiday = 6
ElseIf Month(date)=9 and date > DateSerial(Year(Date),9,7) - Weekday(DateSerial(Year(Date),9,7),3) then
Holiday = 7
ElseIf Month(date)=10 and date < DateSerial(Year(Date),10,15) - Weekday(DateSerial(Year(Date),10,15),3) then
Holiday = 7
ElseIf Month(date)=10 and date > DateSerial(Year(Date),10,15) - Weekday(DateSerial(Year(Date),10,15),3) then
Holiday = 8
ElseIf Month(date)=11 and date < DateSerial(Year(Date),11,11) then
Holiday = 8
ElseIf Month(date)=11 and date < DateSerial(Year(Date),11,29) - Weekday(DateSerial(Year(Date),11,29),6) then
Holiday = 9
ElseIf Month(date)=11 and date > DateSerial(Year(Date),11,29) - Weekday(DateSerial(Year(Date),11,29),6) then
Holiday = 10
ElseIf Month(date)=12 and date < DateSerial(Year(Date),12,25) then
Holiday = 10
Else
Holiday = 11
End if
Dim Hol(10)
' January
Hol(0) = DateSerial(Year(Date),1,22) - Weekday(DateSerial(Year(Date),1,22),3) & " - " & "MLK Day is in " & DateDiff("d",date,DateSerial(Year(Date),1,22) - Weekday(DateSerial(Year(Date),1,22),3)) & " days."
' February
Hol(1) = DateSerial(Year(Date),2,14) & " - " & "Valentine's Day is in " & DateDiff("d",date,DateSerial(Year(Date),2,14)) & " days."
Hol(2) = DateSerial(Year(Date),3,1) - Weekday(DateSerial(Year(Date),3,1),3) - 7 & " - " & "President's Day is in " & DateDiff("d",date ,DateSerial(Year(Date),3,1) - Weekday(DateSerial(Year(Date),3,1),3) - 7) & " days."
' May
Hol(3) = DateSerial(Year(Date),6,1) - Weekday(DateSerial(Year(Date),6,1),3) & " - " & "Memorial Day is in " & DateDiff("d",date,DateSerial(Year(Date),6,1) - Weekday(DateSerial(Year(Date),6,1),3)) & " days."
' July
Hol(4) = DateSerial(Year(Date),7,4) & " - " & "July 4th is in " & DateDiff("d",date,DateSerial(Year(Date),7,4)) & " days."
' September
Hol(5) = DateSerial(Year(Date),9,8) - Weekday(DateSerial(Year(Date),9,8),3) & " - " & "Labor Day is in " &DateDiff("d",date,DateSerial(Year(Date),9,8) - Weekday(DateSerial(Year(Date),9,8),3)) & " days."
' October
Hol(6) = DateSerial(Year(Date),10,15) - Weekday(DateSerial(Year(Date),10,15),3) & " - " & "Columbus Day is in " &DateDiff("d",date ,DateSerial(Year(Date),10,15) - Weekday(DateSerial(Year(Date),10,15),3)) & " days."
' November
Hol(7) = DateSerial(Year(Date),11,11) & " - " & "Veterans' Day is in " & DateDiff("d",date,DateSerial(Year(Date),11,11)) & " days."
Hol(8) = DateSerial(Year(Date),11,29) - Weekday(DateSerial(Year(Date),11,29),6) & " - " & "Thanksgiving Day is in " & DateDiff("d",date,(DateSerial(Year(Date),11,29) - Weekday(DateSerial(Year(Date),11,29),6))) & " days."
' December
Hol(9) = DateSerial(Year(Date),12,25) & " - " & "Christmas Day is in " & DateDiff("d",date,DateSerial(Year(Date),12,25)) & " days."
Hol(10)= DateSerial(Year(Date),12, 31) & " - " & "New Year's Eve Day is in " & DateDiff("d",date,DateSerial(Year(Date),12,31)) & " days." & vbCrLf & " " & DateSerial(Year(DateAdd("yyyy",1,Date)), 1, 1) & " - " & "New Year's Day is in " & DateDiff("d",date,DateSerial(Year(DateAdd("yyyy",1,Date)), 1, 1)) & " days."
SELECT Case Holiday
Case 1 Run(1)
Case 2 Run(2)
Case 3 Run(3)
Case 4 Run(4)
Case 5 Run(5)
Case 6 Run(6)
Case 7 Run(7)
Case 8 Run(8)
Case 9 Run(9)
Case 10 Run(10)
Case 11 Run(11)
END SELECT
' Case Statements for result
Sub Run(var)
Set WS = CreateObject("WScript.shell")
Select Case var
Case 1 For i=0 to 10
msg=msg & " " & hol(i) & vbCrLf & vbCrLf
Next
Msgbox "Today is " & Date & vbCrLf & vbCrLf & Msg , vbInformation, Notice
Case 2 For i=1 to 10
msg=msg & " " & hol(i) & vbCrLf & vbCrLf
Next
Msgbox "Today is " & Date & vbCrLf & vbCrLf & Msg , vbInformation, Notice
Case 3 For i=2 to 10
msg=msg & " " & hol(i) & vbCrLf & vbCrLf
Next
Msgbox "Today is " & Date & vbCrLf & vbCrLf & Msg , vbInformation, Notice
Case 4 For i=3 to 10
msg=msg & " " & hol(i) & vbCrLf & vbCrLf
Next
Msgbox "Today is " & Date & vbCrLf & vbCrLf & Msg , vbInformation, Notice
Case 5 For i=4 to 10
msg=msg & " " & hol(i) & vbCrLf & vbCrLf
Next
Msgbox "Today is " & Date & vbCrLf & vbCrLf & Msg , vbInformation, Notice
Case 6 For i=5 to 10
msg=msg & " " & hol(i) & vbCrLf & vbCrLf
Next
Msgbox "Today is " & Date & vbCrLf & vbCrLf & Msg , vbInformation, Notice
Case 7 For i=6 to 10
msg=msg & " " & hol(i) & vbCrLf & vbCrLf
Next
Msgbox "Today is " & Date & vbCrLf & vbCrLf & Msg , vbInformation, Notice
Case 8 For i=7 to 10
msg=msg & " " & hol(i) & vbCrLf & vbCrLf
Next
Msgbox "Today is " & Date & vbCrLf & vbCrLf & Msg , vbInformation, Notice
Case 9 For i=8 to 10
msg=msg & " " & hol(i) & vbCrLf & vbCrLf
Next
Msgbox "Today is " & Date & vbCrLf & vbCrLf & Msg , vbInformation, Notice
Case 10 For i=9 to 10
msg=msg & " " & hol(i) & vbCrLf & vbCrLf
Next
Msgbox "Today is " & Date & vbCrLf & vbCrLf & Msg , vbInformation, Notice
Case 11 For i=10 to 10
msg=msg & " " & hol(i) & vbCrLf & vbCrLf
Next
Msgbox "Today is " & Date & vbCrLf & vbCrLf & Msg , vbInformation, Notice
End Select
End Sub
Save the File
2) Click Save,
3) Choose the location where to Save this file,
4) Change Save as type: from Text Documents (*.txt) to "All Files",
5) Give the file a name i.e. Holidays.vbs,
6) Click Save.
Congratulations you are done.
Observations & Summary
1) VBS Holiday Countdown is a perpetual holiday calendar, there is no need to make adjustments to the code to allow for leap year.
2) It is small and easy to use.
3) If you wanted to, you can add more or remove holidays.
Summary
I am satisfied with the results.
Then I saw, and considered it well. I looked upon it, and received instruction..