Not Operator

See Also              Example

Used to perform logical negation on an expression.

Syntax

result = Not expr

Remarks

The following table illustrates how result is determined:

If expr is       Then result is

True              False

False             True

Null               Null

In addition, the Not operator inverts the bit values of any variable and sets the corresponding bit in result according to the following truth table:

Bit in expr     Bit in result

0                   1

1                   0

If an integer variable has the value 0 (False), the variable becomes -1 (True); if it has the value -1, it becomes 0.

See Also

Arithmetic Operators

Comparison Operators

Concatenation Operators

Logical Operators

Operator Precedence

Not Operator Example

The example displays a message that depends on the value of variables A and B, assuming neither variable is a Null.  If A = 10 and B = 8, the Not expression evaluates True because A is not equal to B.  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, Msg                         ' Declare variables.

A = 10: B = 8                         ' Assign values.

If Not A = B Then                     ' Evaluate expression.

Msg = "A and B aren't equal."

Else

Msg = "A and B are equal."

End If

MsgBox Msg                            ' Display results.

End Sub