Completing Calendars with VBScript Date Functions
(Page 1 of 4 )
In my last article, we began building a script that could produce and display a formatted calendar for a specified month and year. In this article, I’ll show you how to wrap up this project by putting all of the pieces together.We began our script by accepting a user’s input for the month and year. We then used those two values to determine all of the other necessary values we would need, such as the first day of the month, the weekday that the first falls on, and the last day of the month. Now we can complete the main portion of our script.
We need to begin building an array to handle the dates involved in our calendar month. This array will contain each day in the month. I elected to house this in a separate function.
arrThisMonth = BuildArray()
The BuildArray function is only slightly complicated. Let’s take a look at it in pieces.
Function BuildArray()
arrMonth = Array()
intEmptyDays = intFirstWeekDay - 1
For i = 1 To intEmptyDays
ReDim Preserve arrMonth(UBound(arrMonth) + 1)
arrMonth(UBound(arrMonth)) = " "
Next
It begins by creating an empty dynamic array. If you remember, a calendar week always begins on Sunday. The first day of the month may not be on Sunday, so we need to determine the number of empty days before it. Since the WeekDay function has returned an integer for the weekday of the first month, we can just subtract 1 from this value to determine the number of empty days in that week.
For example, if Jan 1 were to appear on Thursday (a value of 5), there would be 5 minus 1, or 4, empty days preceding it: Sunday, Monday, Tuesday and Wednesday.
Next: Building the array >>
More Windows Scripting Articles
More By Nilpo