Operators & Their Order of Precedence

 


TABLE OF CONTENTS


When operators from more than one of the categories below exist in an expression, arithmetic operators are evaluated first, comparison operators next, and logical operators last.

  

Arithmetic Operators

Processed?

Operator

Description

1st 

( . . .)

Whatever's enclosed by parentheses gets processed first (use these to avoid any ambiguity)

2nd

-

Negation--indicates a negative expression

3rd 

^

Exponentiation-- raising a number to a power

4th

*

Multiplication

/

Normal Division

5th

\

Integer Division

Mod

Modulo Operator-- returns a remainder

6th

Subtraction

+

Addition

7th

&

Although not strictly an arithmetic operator, the string concatenation operator is evaluated before comparison and logical operators

8th

IS

Actually an object reference operator, tests whether one object is identical to another 

NOTES:

  • When addition and subtraction both occur in an expression, evaluation of the expression proceeds from left to right.
  • Within parentheses, left-to-right precedence applies.

 

Back to Top

 

 

Comparison Operators (in order of precedence)

Processed?

Operator

Description

All have equal precedence; so they're evaluated in the left-to-right order in which they appear

=

Equal to

<>

Not Equal to

<

Less than

>

Greater than

<=

Less than or equal to

>=

Greater than or equal to

LIKE

Actually a pattern matching operator, tests whether two expressions are equal

 

Back to Top

 


Logical Operators (in order of precedence)

Processed?

Operator

Description

1st

Not

Reverses the value of a logical expression. (Avoid using if at all possible using it tends to make the code harder to understand)

2nd

And

If both expressions are true, the result is true

3rd

Or

If one of the expressions is true, the result is true

4th

Xor

Exclusive OR

5th

Eqv

Performs a bitwise comparison by bit position between two numeric expressions. If either expression is Null, the result is also Null. If neither expression is null then the result is determined using the following:

  If       And     Then

expr1 is  expr 2 is  the result is

True       True       True

True       False       False

False      True       False

False      False       True

6th

Imp

Performs a bitwise comparison by bit position between two numeric expressions. The result of an imp operation is determined as follows:

  If       And     Then

expr1 is  expr 2 is  the result is

True       True       True

True       False       False

True       Null        Null

False      True       True

False      False       True

False      Null        True

Null       True       True

Null       False       Null

Null       Null        Null

Back to Top

arrowl2Return to the Visual Basic 6 Commands & Functions Page

Comments

 

Latest Version! NetObjects Fusion 10 

 

Copyright 1998 Rich Hamper 

All Rights Reserved

 

Last Updated:

Sunday, January 20, 2008