如果通过"比较"表示"它们是同一类型吗?",您可以使用TypeName函数:
If (object1 <> Nothing) and (object2 <> Nothing) then
If (TypeName(object1) = TypeName(object2)) Then
Debug.Print "object types are the same"
Else
Debug.Print "object types are NOT the same"
End If
End If
Run Code Online (Sandbox Code Playgroud)
如果通过"比较"表示"它们是否在内存中引用相同的对象?",则可以使用Is运算符:
If (object1 Is object2) Then
Debug.Print "objects references are the same"
Else
Debug.Print "objects references are NOT the same"
End If
Run Code Online (Sandbox Code Playgroud)
对于其他可能想知道同一问题的人:
经过大量研究后,VB6 似乎没有像 Java 那样的任何类型的内置函数compareTo或equals方法。
我忘了在Java中,compareTo是在java.lang.Comparable接口中定义的。由于 VB6 中的接口非常糟糕,即使您编写了自己的Comparable接口,您也必须调用对象的Comparable_compareTo方法,除非它被声明为Comparable,这是毫无意义的。
底线:如果您想要VB6 类中的compareTo方法equals,只需将它们放入即可。