XOR Operator

See Also3YAVGDE              ExampleGUF7FM>Low

Used to perform a logical exclusion on two expressions.


result = expr1 Xor expr2


If only one of the expressions evaluates True, result is True.  If either expression is a Null1DDW7C0 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 expressions71RISN and sets the corresponding bit in result according to the following truth table:


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


See Also

Arithmetic OperatorsSH0K1B

Comparison OperatorsNRJZ1K

Concatenation Operators2MYTW1K

Logical Operators1CQVUTN

Operator Precedence23082A9

Other Operators2HA580P

Xor Operator Example

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."


      Msg = "Both comparison expressions are True or both are False."

   End If

   MsgBox Msg                            ' Display results.

End Sub