Used to perform a logical disjunction on two Boolean expressions, or bitwise disjunction on two numeric values..
result = expression1 Or expression2
For Boolean comparison, if either expression1 or expression2 evaluates to True, result is True. If expression1 evaluates to True, and expression2 evaluates to False the result is True. The following table illustrates how result is determined:
If expression1 is | And expression2 is | Then result is |
---|---|---|
True | True | True |
True | False | True |
False | True | True |
False | False | False |
For bitwise operations, the Or operator performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table:
If bit in expression1 is | And bit in expression2 is | Then result is |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
Note Since the logical/bitwise operators have a lower precedence than other arithmetic and relational operators, any bitwise operations should be enclosed in parentheses to insure accurate execution.
If the operands consist of one Boolean expression and one numeric expression, the result Boolean expression will be converted to a numeric value (-1 for True, and 0 for False) and the bitwise operation will result.
This example uses the Or operator to perform logical disjunction on two expressions. The result is a Boolean value that represents whether either of the two expressions is true.
Dim A As Integer = 10 Dim B As Integer = 8 Dim C As Integer = 6 Dim myCheck As Boolean myCheck = A > BOr
B > C ' Returns True. myCheck = B > AOr
B > C ' Returns True. myCheck = B > AOr
C > B ' Returns False.
This example uses the Or operator to perform logical disjunction of the individual bits of two numeric expressions. The bit in the result pattern is set if either of the corresponding bits in the operands are set.
Dim A As Integer = 10 Dim B As Integer = 8 Dim C As Integer = 6 Dim myCheck As Integer myCheck = (A Or B) ' Returns 10. myCheck = (A Or C) ' Returns 14. myCheck = (B Or C) ' Returns 14.
Logical/Bitwise Operators | Operator Precedence in Visual Basic | Operators Listed by Functionality | OrElse Operator |