See Also Example
Used to perform a logical exclusion on two expressions.
Syntax
result = expr1 Xor expr2
Remarks
If only one of the expressions evaluates True, result is True. 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 And expr2 The result
is is is
True True False
True False True
False True True
False False False
The Xor operator also performs a bit-wise comparison of identically positioned bits in two numeric expressions
If bit in And bit in The result
expr1 is expr2 is is
0 0 0
0 1 1
1 0 1
1 1 0
Arithmetic Operators
Comparison Operators
Concatenation Operators
Logical Operators
Operator Precedence
Other Operators
The example displays 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. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim A, B, C, Msg ' Declare variables.
A = 6: B = 8: C = 10 ' Assign values.
If A > B Xor B = C Then ' Evaluate expressions.
Msg = "Only one comparison expression is True, not both."
Else
Msg = "Both comparison expressions are True or both are False."
End If
MsgBox Msg ' Display results.
End Sub