Export (0) Print
Expand All

Or Operator

Used to perform a logical disjunction on two Boolean expressions, or bitwise disjunction on two numeric values..

result = expression1 Or expression2

Parts

result
Required. Any Boolean or numeric expression. For Boolean comparison the result is the logical disjunction of two expressions. For bitwise operations the result is a numeric value resulting from the bitwise disjunction of two numeric expressions.
expression1
Required. Any Boolean or numeric expression.
expression2
Required. Any Boolean or numeric expression of the same type as expression1.

Remarks

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

Example

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 > B Or B > C   ' Returns True.
myCheck = B > A Or B > C   ' Returns True.
myCheck = B > A Or 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.

See Also

Logical/Bitwise Operators | Operator Precedence in Visual Basic | Operators Listed by Functionality | OrElse Operator | Logical Operators

Show:
© 2014 Microsoft