Visual Basic Language Reference  

Is Operator

Compares two object reference variables.

result = object1 Is object2

Parts

result
Required. Any Boolean value.
object1
Required. Any Object name.
object2
Required. Any Object name.

Remarks

The Is operator determines if two object references refer to the same object. However, it does not perform value comparisons. If object1 and object2 both refer to the same object, result is True; if they do not, result is False.

Example

This example uses the Is operator to compare two object references. The object variable names are generic and used for illustration purposes only. The result is a Boolean value representing whether the two objects are identical.

Dim myObject, otherObject As New Object
Dim yourObject, thisObject, thatObject As Object
Dim myCheck As Boolean
yourObject = myObject
thisObject = myObject
thatObject = otherObject
myCheck = yourObject Is thisObject   ' Returns True.
myCheck = thatObject Is thisObject   ' Returns False.
myCheck = myObject Is thatObject ' Returns False, if myObject is not thatObject.

See Also

Comparison Operators | Operator Precedence in Visual Basic | Operators Listed by Functionality | Operators