Building Calendars with VBScript Date Functions - Beginning the script
(Page 2 of 4 )
The challenge also stated that the script should be written for (and would be tested using) the Cscript.exe engine. For our purposes, I think it’s best to force the use of the Cscript.exe host by beginning our script with the following code.
If LCase(Right(WScript.FullName, 11)) <> "cscript.exe" Then
strPath = WScript.ScriptFullName
strCommand = "%comspec% /k cscript " & Chr(34) & strPath & chr(34)
CreateObject("WScript.Shell").Run(strCommand)
WScript.Quit
End If
Very simply, this code snippet uses the WScript object’s FullName property to determine in which host engine the script is running. If it is not Cscript, then the script calls itself from the command line in the proper engine, and then terminates itself.
It is important that our script runs in Cscirpt.exe. You saw in the example on the last page that the calendar spans several lines. If the script were to run in Wscript.exe, each of these lines would result in a separate message box. For obvious reasons, we don’t want that.
If you really wanted to run this script in Wscript, you could. Instead of outputting each line in the script, you would add a line feed character and append them in a single string. This string could then be displayed in a message box. However, message boxes do not use mono-spaced, so the columns would not line up properly.
Next: Finding the necessary dates >>
More Windows Scripting Articles
More By Nilpo