contents.gifindex.gif

Xor Operator

Purpose

Used to perform a logical exclusion on two expressions.

Syntax

result = expr1 Xor expr2

Notes

The Xor operator is a logical exclusive Or operator used to evaluate two expressions. If only one of the expressions evaluates true (nonzero), result is True (-1). If either expression is a Null, result is also a Null. When neither expression is a Null, result is determined according to the following table.

If expr1 is
And expr2 is
result is


true (nonzero)
true
False (0)
true
false (0)
True (-1)
false
true
True
false
false
False


The Xor operator also performs a bit-wise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following truth table.

If bit in expr1 is
And bit in expr2 is
result is


0
0
0
0
1
1
1
0
1
1
1
0


Bit-wise comparisons can be performed only in Access Basic.

Example

This example prints a message depending on the value of the variables A, B, and C, assuming that no variable is a Null. If A = 6, B = 8, and C = 10, both expressions evaluate False. Because both are False, the Xor expression is also False.

If A > B Xor B = C Then

Debug.Print "Only one comparison expression is True, not both."

Else

Debug.Print "Both comparison expressions are True or both are False."

End If