() (keyword)

Syntax 1


Syntax 2



Forces parts of an expression to be evaluated before others or forces a parameter to be passed by value.


Parentheses within Expressions

Parentheses override the normal precedence order of the scripts operators, forcing a subexpression to be evaluated before other parts of the expression. For example, the use of parentheses in the following expressions causes different results:

  i = 1 + 2 * 3     'Assigns 7.
  i = (1 + 2) * 3   'Assigns 9.

Use of parentheses can make your code easier to read, removing any ambiguity in complicated expressions.


Parentheses Used in Parameter Passing

Parentheses can also be used when passing parameters to functions or subroutines to force a given parameter to be passed by value, as shown below:

  ShowForm i      'Pass i by reference.
  ShowForm (i)     'Pass i by value.

Enclosing parameters within parentheses can be misleading. For example, the following statement appears to be calling a function called ShowForm without assigning the result:


The above statement actually calls a subroutine called ShowForm, passing it the variable i by value. It may be clearer to use the ByVal keyword in this case, which accomplishes the same thing:

  ShowForm ByVal i

The result of an expression is always passed by value.


This example uses parentheses to clarify an expression.

Sub Main()
  bill = False
  dave = True
  jim = True

  If (dave And bill) Or (jim And bill) Then
    Msgbox "The required parties for the meeting are here."
    MsgBox "Someone is late for the meeting!"
  End If
End Sub

See Also

ByVal (keyword); Operator Precedence (topic).

More information