Operator Precedence


© Maxim Karetnikov

When VBScript encounters an expression that contains several different operators, a basic precedence order is followed to evaluate the expression. This predetermined order of evaluating operators is known as operator precedence. Since the portions of an expression that are placed within parentheses are evaluated first, you can use parentheses within your expression to override the operator precedence and force some portions of your expression to be evaluated before other portions. Within the parentheses, however, VBScript maintains normal operator precedence. Table 1 shows the order of precedence for VBScript operators.

Table 1. Precedence for VBScript
Precedence Order Operation

Arithmetic

1

Exponents (^)

2

Negation (-)

3

Multiplication (*), division (/ and \)

4

Modulo arithmetic (Mod)

5

Addition (+), subtraction (-)

Comparison

1

Equality (=)

2

Inequality (<>)

3

Less than (<)

4

Greater than (>)

5

Less than or equal to (<=)

6

Greater than or equal to (>=)

Logical

1

Negation (Not)

2

Conjunction (And)

3

Disjunction (Or)

4

Exclusion (Xor)

5

Logical equivalence (Eqv)

6

Implication (Imp)

When expressions contain operators from more than one category, computational operators are evaluated first, concatenation operators are evaluated next, then comparison operators are evaluated, and logical operators are evaluated last. Comparison operators all have equal precedence; that is, they are evaluated in the left-to-right order in which they appear. Arithmetic and logical operators are evaluated in order of precedence.

When multiplication and division occur together in an expression, each operation is evaluated as it occurs from left to right. Likewise, when addition and subtraction occur together in an expression, each operation is evaluated in order of appearance from left to right.

Go To Page: 1 2


The copyright of the article Operator Precedence in VB Script is owned by . Permission to republish Operator Precedence in print or online must be granted by the author in writing.

Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo