I\'m facing something weird in VBScript. When writing a procedure where I want the parameter to be passed by reference, the way of calling this procedure changes the way the
To be clear. Parentheses have three different purposes.
There are two ways to call a procedure either as a statement or as an expression.
Expression:-
x = func(y)
Statement:-
func y
Note the Call keyword invokes the procedure as if it were part of an expression hence the argument list must be contained in parantheses.
In the above that y itself represents a very simple expession. We could well have used y + z at this point. In fact we can use any valid expression at this point, including one that uses the parentheses operator. For example:-
x = (y)
is a valid expression. Hence when you do:-
func(y)
VBScript sees the call to func to which the result of the expression (y) is passed. Now even if func defines this parameter as ByRef the value in y would be unaffected because y wasn't actually passed as a parameter. What was passed was the result of the expression (y) which would be stored somewhere temporary. Even if this temporary store is modified by func it would be discarded afterwards and hence has the same behaviour had the parameter been marked ByVal.