I have the following VBScript code:
Dim returnVal
returnVal = "You did not pass me 4 arguments"
args = WScript.Arguments.Count
If args = 4 Then
returnVal = "The arguements you passed me are " & WScript.Arguments.Item(0) & " " & WScript.Arguments.Item(1) & " " & WScript.Arguments.Item(2) & " " & WScript.Arguments.Item(3)
end if
All I want is the ability to print “returnVal” so that if I typed:
test.vbs 1 2 3 4
It would return:
The arguments you passed me are 1 2 3 4
How can I do this?
To output to the command console window you can do this using:
or
But you must use the CScript host for this to work, for example:
WScript is the GUI host and so has no knowledge of the standard input/output/error/aux streams. Trying to do
WScript.StdOut.WriteLinewill result in the following error dialogue:In a CScript.exe script you can still pop up GUI message dialogues using:
Using
WScript.Echoin a WScript host will display the message in a popup dialogue instead of printing to the command line window.For more information see:
For more information on the differences between WScript and CScript and how to switch between them: