||In VBScript, the general rule is that you cannot place parenthesis around the arguments you are calling a sub with, unless you prefix the subroutine call with the |
Call keyword like so:
'This will generate an error
MySub(Param1, Param2, Param3)
'To use parens for a Sub, you must use the Call statement
'This is legal syntax
Call MySub(Param1, Param2, Param3)
However, if this is true, then why can you sometimes use parens when calling subroutines? For example,
Response.Write is a subroutine call, and the VBScript engine doesn't barf when you do:
'This works... but should it?
Shouldn't you need to prefix the above line of code with the
Call statement? Notice that the only time VBScript doesn't barf when using parens when calling a sub is when you are passing just one parameter and the parameter can be evaluated as an expression (a string, integer, equation, etc.). This is because, according to the VBScript language rules, when it sees parens around a parameter to a sub, it assumes you want to evaluate what is in the parens first, and pass that information to the sub. Such behavior removes the ambiguity between these two statements:
The first line will call MySub passing a value of 4 and adding 5 to the result. The second line will pass in the value of 9 to
MySub. Note that the parens didn't cause an error (even though
MySub is a sub, and shouldn't allow such behavior). This is because such syntax is interpretted to evaluate the expression
4 + 5 and then pass the value into the Sub.
For more information on this phenomenon, be sure to read the great article: Using Parenthesis in VBScript when Calling a Subroutine.