Operators

Operator Precedence

LevelOperators
1unary -, unary +
2*, /
3MOD
4+, -
5&
6<<, >>
7=, <, >, <=, >=, <>
8NOT
9AND, ANDALSO
10OR, ORELSE
11XOR

Operators at level one have the highest precedence, with operators at level seven having the lowest precedence. Parentheses can be used to override the order of precedence rules, allowing parts of an expression to be evaluated before others.

Relational Operators

The operators used for comparison are called relational operators. Applying a relational operator will yield a result of true or false.

OperatorMeaning
=Is equal to
<Is less than
>Is greater than
<=Is less than or equal to
>=Is greater than or equal to
<>Is not equal to

The only relational operators supported for string types are equal and not equal, unless the string is being compared against nothing., in which case "is" and "isnot" may be used. Because the internal binary representation of floating point numbers may not be exact, the equality operator should be avoided for floating point numbers.

Mathematical Operators

OperatorMeaning
*Multiply
/Divide
+Addition
-Subtraction
MODModulus

In addition to the mathematical operators shown above, you can use the unary operator to change the sign. For example,

Sub Main()
   Dim Value As SByte
   Value = 10     ' Value = 10
   Value = -Value ' Value = -10
End Sub

Logical Operators

OperatorMeaning
NOTNegate
ANDLogical AND
ORLogical OR
XORLogical XOR

Logical operators can be used to build conditional expressions, for example, when using if…then, while…end while and do…repeat until statements. Applying a boolean operator yields either true or false.

Bitwise Operators

The following operators perform bitwise manipulation on integer operands.

OperatorMeaning
NOTA bitwise NOT or complement
ANDBitwise AND
ORBitwise OR
XORBitwise XOR
<<Shift Left
>>Shift Right