Tuesday, December 16, 2008

[vb6] Use the IS operator to compare objects

With ordinary variables you would use the = operator to compare different variables. This does not work with object variables. Instead you have to use the IS operator, e.g.:
    Dim MyObject as MyClass
Dim MyOtherObject as MyClass

Set MyObject = New MyClass
Set MyOtherObject = MyObject

'Now, the two object variables reference the same object.

If MyOtherObject Is MyObject Then
'The message box should pop up:
MsgBox "Yes, MyObject points to the same object as MyOtherObject and vice versa"
End If
The IS operator must be used within an If - Then statement.

No comments:

Post a Comment