Export (0) Print
Expand All

Not Operator

Performs logical negation on a Boolean expression, or bitwise negation on a numeric expression.

result = Not expression

Parts

result
Required. Any Boolean or numeric expression.
expression
Required. Any Boolean or numeric expression.

Remarks

For Boolean expressions, the following table illustrates how result is determined:

If expression is Then result is
True False
False True

For numeric expressions, the Not operator inverts the bit values of any numeric expression and sets the corresponding bit in result according to the following table:

If bit in expression is Then bit in result is
0 1
1 0
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.

Example

This example uses the Not operator to perform logical negation on a Boolean expression. The result is a Boolean value representing whether the expression is false. That is, if the expression is false, the result of the Not operator is true.

Dim A As Integer = 10
Dim B As Integer = 8
Dim C As Integer = 6
Dim myCheck As Boolean
myCheck = Not(A > B)   ' Returns False.
myCheck = Not(B > A)   ' Returns True.

This example uses the Not operator to perform logical negation of the individual bits of two numeric expressions. The bit in the result pattern is set to the reverse of the corresponding bit in the operand pattern, including the sign bit.

Dim A As Integer = 10
Dim B As Integer = 8
Dim C As Integer = 6
Dim myCheck As Integer
myCheck = (Not A)   ' Returns -11.
myCheck = (Not B)   ' Returns -9.
myCheck = (Not C)   ' Returns -7.

See Also

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

Show:
© 2014 Microsoft