Microsoft Office Tutorials and References
In Depth Information
The Logical Operators
You use logical operators to manipulate logical (True/False) expressions. Most of the logical
operators combine two logical expressions into a single logical value. The logical operators are described
in Table 23.2.
TABLE 23.2
The Logical Operators
X And Y
True if both X and Y are True; False otherwise.
X Or Y
True if X or Y , or both of them, are True; False only if both X and Y are
Xor (exclusive Or )
X Xor Y
True if X and Y are different (one True and the other False); False if
both are True or both are False.
Eqv (Equivalence)
X Eqv Y
True if X and Y are the same (both True or both False); False otherwise.
Imp (Implication)
X Imp Y
False only if X is True and Y is False; True otherwise.
Not X
True if X is False, False if X is True.
The logical operators are often used in conjunction with the comparison operators. For example,
the following expression evaluates as True only if x is equal to 5 and y is not equal to 0:
(x = 5) And (y <> 0)
Operator Precedence and Parentheses
When an expression contains more than one operator, it may not always be clear how the
expression evaluates. For example, look at this expression:
20 / 4 + 6
How should you read this?
n If the addition is performed first, the expression evaluates to 2 (4 plus 6 is 10, 20 divided
by 10 is 2)
n If the division is performed first, the result is 11 (20 divided by 4 is 5, 5 plus 6 is 11).
Potentially ambiguous expressions such as this one are resolved by VBA’s rules of operator
precedence , which determine the order in which operations are performed. The precedence of VBA’s
operators is given in Table 23.3. Operators with lower precedence numbers are performed first.
Search JabSto ::

Custom Search