Conditional Expressions
When performing actions based upon how a condition evaluates, there are numerous ways to build the condition. For example, when writing an If statement, you can compare a field to a constant using a variety of relational operators and you can join multiple conditions using Boolean operators. This section shows you all the ways you can evaluate fields and variables to see whether they match a certain value or a range of values.
You can test against a single constant or variable using the standard relational opera<, >, <=, >=, =, <>.
You can also compare multiple expressions using the standard Boolean operators: And, Or, Not. A few operators that might be new to you are Xor, Eqv and Imp.
Eqv is for logical equivalence. It determines when the two expressions are the same. It returns True when both are true or both are false. If they are not the same, it returns False. The syntax is as follows:
exp1 Eqv exp2
Xor is for logical exclusion. It determines when the two expressions are different. It returns True if one is true and the other false. If both expressions are either true or false, then it returns False. The syntax is as follows:
exp1 Xor exp2
Imp is for logical implication. If the first expression is true, it implies that the second expression will also be true. If the second expression is also true, Imp returns True. If the second expression is False, Imp returns False because it didn’t meet what was implied. On the other hand, if the first expression is False, nothing is implied and the result will be always be True. Thus, there is only one instance where Imp returns False: when the first expression is True and the second expression is False. The syntax is as follows:
exp1 Imp exp2
The Is operator is used with the Select Case statement when you want to use the relational operators (e.g. >, <, etc.). An example demonstrating this was already shown in the discussion on the Select Case statement.
The In operator is used for testing if a field or variable exists as an element in an array or if it falls within a range of values. For more information, see the previous sections Array Data Types and Range Data Types.