Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To my knowledge these are the rules for calling subroutines and functions in VBScript:</p> <ul> <li>When calling a subroutine or a function where you discard the return value don't use parenthesis</li> <li>When calling a function where you assign or use the return value enclose the arguments in parenthesis</li> <li>When calling a subroutine using the <code>Call</code> keyword enclose the arguments in parenthesis</li> </ul> <p>Since you probably wont be using the <code>Call</code> keyword you only need to learn the rule that <strong>if you call a function and want to assign or use the return value you need to enclose the arguments in parenthesis. Otherwise, don't use parenthesis.</strong></p> <p>Here are some examples:</p> <ul> <li><p><code>WScript.Echo 1, "two", 3.3</code> - calling a subroutine</p></li> <li><p><code>WScript.Echo(1, "two", 3.3)</code> - syntax error</p></li> <li><p><code>Call WScript.Echo(1, "two", 3.3)</code> - keyword <code>Call</code> requires parenthesis</p></li> <li><p><code>MsgBox "Error"</code> - calling a function "like" a subroutine</p></li> <li><p><code>result = MsgBox("Continue?", 4)</code> - calling a function where the return value is used</p></li> <li><p><code>WScript.Echo (1 + 2)*3, ("two"), (((3.3)))</code> - calling a subroutine where the arguments are computed by expressions involving parenthesis (note that if you surround a variable by parenthesis in an argument list it changes the behavior from call by reference to call by value)</p></li> <li><p><code>WScript.Echo(1)</code> - apparently this is a subroutine call using parenthesis but in reality the argument is simply the expression <code>(1)</code> and that is what tends to confuse people that are used to other programming languages where you have to specify parenthesis when calling subroutines</p></li> <li><p>I'm not sure how to interpret your example, <code>Randomize()</code>. <code>Randomize</code> is a subroutine that accepts a single optional argument but even if the subroutine didn't have any arguments it is acceptable to call it with an empty pair of parenthesis. It seems that the VBScript parser has a special rule for an empty argument list. However, my advice is to avoid this special construct and simply call any subroutine without using parenthesis.</p></li> </ul> <p>I'm quite sure that these syntactic rules applies across different versions of operating systems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload