Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cscript.exe and %errorlevel% , Variable is undefined

Status
Not open for further replies.

aauricch

MIS
Nov 2, 2002
4
0
0
CH
When the "option explicit" is set and a variable
is used before it is declared the the following exception
occurs :
"Microsofr VBScript runtime error: Variable is undefined".
At this time nothing strange on this behaviuor.
On a W2000 this script is started from a cmd windows:
cscript.exe MyScript.vbs
When I analyze the variable %errorlevel% this is set to 0.
Usually I will expect that the %errorlevel% variable will be set to something > than 0.
Someone could me why cscript has this behaviour?
 
The error is occuring at compile of the script before it executes. Because of this there is no error level or exit code to return.

Keep using OPTION EXPLICIT. It's good practice to declare before using.

I find it also helps to group my variable declarations at the top of the script or function. This both forces me to think before writing as well as making it easier to trouble shoot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top