Building Calendars with VBScript Date Functions - Finding the necessary dates
(Page 3 of 4 )
Before we can do anything at all, our script needs to get the user’s input so that it can determine from what month and year the calendar needs to build. There are two ways of doing this.
strDate = InputBox("Please enter a month and year as MM/YYYY.", "Microsoft Scripting Games 2008")
If strDate = "" Then WScript.Quit
The most obvious is to use a simple input box to receive the user input as a string. Notice in the second line that I’ve provided a little conditional statement that will end script execution if the user presses the cancel button.
WScript.StdOut.Write "Please enter a month and year as MM/YYYY:"
strDate = WScript.StdIn.ReadLine
The second option relies on the fact that our script is running in Cscript.exe. It uses the Standard Input and Output streams to receive the user’s input from within the command window.
arrDateParts = Split(strDate, "/")
intMonth = arrDateParts(0)
intYear = arrDateParts(1)
Regardless of which method you use, you should end up with the same type of string. Now is a good time to break that into parts so that we have separate date and year values. Since we know what character is being used to separate the values, VBScript’s Split function makes quick work of this, and the values can be assigned to variables in just a few simple lines.
Next: Calculating the remaining values >>
More Windows Scripting Articles
More By Nilpo