Building Calendars with VBScript Date Functions
(Page 1 of 4 )
Every year the Microsoft Scripting Guys host a scripting challenge known as the Microsoft Scripting Games as a sort of Olympics for Windows scripters. This past year presented an interesting challenge that provided an excellent opportunity to use some of VBScript’s Date functions that I’ve been covering in my last couple articles.
There are probably a few different ways to accomplish the task I’ll be presenting you with, but the example you see here is my actual submission for this event. I believe it offers a very efficient and somewhat elegant approach to the challenge.
The challenge was simple. Participants had to write a script capable of outputting a calendar for a specified month as in the example below. The script had to allow a user to specify the month and year and then perform the correct calculations to produce the calendar for the given month in the given year.
September 2008
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
“What’s the point?” You ask.
I don’t know. Maybe you want to know on what day of the week Napoleon was born. [It was a Tuesday. --Ed.]
While the challenge did not require the calendar to be as neatly formatted as you see above, it’s not difficult at all to add the simple padding between columns, so I saw no reason not to. Participants were also not required to validate user input. It was assumed that the user would only input a correct month and year. Validation is not very hard to do. Those who would like to add validation can learn how at the end of this article series.
Next: Beginning the script >>
More Windows Scripting Articles
More By Nilpo