## Operational Precedence

Chapter 4 listed the operational precedence of various numeric operators used in an expression. All these rules still hold for all conditional expressions used in an If statement, but now there are two more types of operators: relational and logical operators. How are these new operators ranked? These new operators rank lower in their operational precedence than any of the numeric operators. In addition, the relational operators have precedence over the logical operators, among which Not has the highest precedence followed by And. The following is the list of operators again, ranking from the highest to the lowest in operational precedence:

- Power (^)
- Unary negation (-)
- Multiplication and division (*, /)
- Integer division (\)
- Remainder (Mod)
- Addition and subtraction (+, -)
- Equal (=)
- Not equal (<>)
- Less than, Greater than (<, >)
- Greater than or equal to (>=)
- Less than or equal to (<=)
- Not
- And, AndAlso
- Or, OrElse and Xor

Too many rules to remember? If you think so, use parentheses to explicitly express the order of operations. Parentheses help add clarity to what needs to be done first.

Try This |

Want to verify that the And operator actually takes precedence over the Or operator? Consider the following code: |

MsgBox(True Or True And False) |

If Or and And rank equal in precedence, the result should be False; however, if And has the precedence, the result should be True.
Enter the code in the form’s click event, run the program, and click the form. What do you see? |

Now you have seen how relational and logical operators work. These operators are used to construct logical expressions, which most likely are used in If statements. It is time to take a closer look at the If statement (block).

**Last change:** February 13 2016 18:47:58.