Operador Is

Contingut

# Is Operator

Tests if two Basic variables refer to the same object instance.

### Sintaxi:

result = oObj1 Is oObj2

If oObj1 and oObj2 are references to the same object instance, the result will be True.

### Exemple:

The example below first defines a new type Student. Calling TestObjects creates the object oStudent1 as a new object of this type.

The assignment oStudent2 = oStudent1 actually copies the reference to the same object. Hence the result of applying the Is operator is True.

        Type Student
            FirstName as String
            Program as String
        End Type

        Sub TestObjects
            Dim oStudent1 as new Student
            Dim oStudent2 as Variant
            oStudent2 = oStudent1
            MsgBox Student1 Is Student2 ' True
        End Sub

The example below returns False because oStudent1 and oStudent2 are references to two different object instances, each created with the New operator.

        Sub TestObjects_v2
            Dim oStudent1 as new Student
            Dim oStudent2 as new Student
            MsgBox oStudent1 Is oStudent2 ' False
        End Sub

Temes relacionats

EqualUnoObjects Function

IsObject Function

Type Statement

Ens cal la vostra ajuda!