ObjectStatic: Equals |
Checks the equality of the two values.
Public Function Equals( ByRef ObjA As Variant, ByRef ObjB As Variant ) As Boolean
The two values must be of the same type to successfully be compared. For example a vbLong value of 1 will not be considered equal to a vbInteger value of 1.
If objects are passed in, an attempt to access the IObject interface is made to allow objects perform their own equality check. If the object does not implement the IObject interface, object references are compared.
This example compare various values using the Equals method.
Public Sub Main() Dim List1 As ArrayList Dim List2 As ArrayList ' Show how numeric values compare differently. PrintEquality 1, 1 PrintEquality CLng(1), CInt(1) PrintEquality "1", 1 ' Set lists to two different instances. Set List1 = New ArrayList Set List2 = New ArrayList PrintEquality List1, List2 ' Set lists to same instance. Set List2 = List1 PrintEquality List1, List2 PrintEquality Nothing, Nothing End Sub Private Sub PrintEquality(ByRef a As Variant, ByRef b As Variant) Dim Relationship As String Relationship = IIf(Object.Equals(a, b), "=", "<>") Debug.Print CorString.Format("{0} '{1}' {2} {3} '{4}'", TypeName(a), a, Relationship, TypeName(b), b) End Sub ' This example code produces the following output. ' ' Integer '1' = Integer '1' ' Long '1' <> Integer '1' ' String '1' <> Integer '1' ' ArrayList 'CorLib.ArrayList' <> ArrayList 'CorLib.ArrayList' ' ArrayList 'CorLib.ArrayList' = ArrayList 'CorLib.ArrayList' ' Nothing '' = Nothing ''