How to check the value of wscript.arguments(0) without two if statements

wsh

Solution

The answer is you can't do it because VBScript has no short-circuit and operator.

Since this is out of curiousity, you can check these links :

http://en.wikipedia.org/wiki/Short-circuit_evaluation

VBScript conditional short-circuiting workaround

Problem

I want to be able to check the value of the first passed argument to a windows script. But I want to be able to do it in such a way that the script will not give a runtime error if there are no arguments passed. This is only a matter of curiosity as I am able get my script working with two if statements, but I want to know if there's a way to do it with just one (like ``` monthly = false if wscript.arguments.count > 0 then if wscript.arguments(0) = "monthly" then monthly = true end if end if ``` It would be neater if this could be done... ``` if wscript.arguments.count > 0 and wscript.arguments(0) = "Monthly" then monthly = true end if ``` But that gives a subscript out of range error because the scripting engine is trying to check the value of an array item that doesn't exist. I know I can do this type of check in PHP (`if(isset($_POST['somevariable'])) && $_POST['somevariable'] == 'somevalue'`)

Original source