Is Operator

Description

Used to compare two object reference variables.

Syntax

result = object1 Is object2

The Is operator syntax has these parts:

Part

Description

result

Any numeric variable.

object1

Any object name.

object2

Any object name.


Remarks

If object1 and object2 both refer to the same object, result is True; if they do not, result is False. Two variables can be made to refer to the same object in several ways.

In the following example, A has been set to refer to the same object as B:


Set A = B

The following example makes A and B refer to the same object as C:


Set A = CB = C

See Also

Comparison Operators.

Example

This example uses the Is operator to compare two object references. The object variable names are generic and used for illustration purposes only.


Set YourObject = MyObject            ' Assign object references.ThisObject = MyObjectThatObject = OtherObject= YourObject Is ThisObject    ' Returns True.= ThatObject Is ThisObject    ' Returns False.
' Assume MyObject <> OtherObject= MyObject Is ThatObject        ' Returns False.