|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Used to perform a logical disjunction on two Boolean expressions, or bitwise disjunction on two numeric values..
result = expression1 Or expression2
- 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.
- Required. Any Boolean or numeric expression.
- Required. Any Boolean or numeric expression of the same type as expression1.
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|
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|
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.
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.