VBA:如何测试对象是否相等(两个变量是否引用同一个对象)
测试相同自定义对象类型的两个变量是否引用同一对象的运算符或函数是什么?我已经尝试过
What is the operator or function to test whether two variables of the same custom object type refer to the same object? I've tried
If myObject = yourObject Then
但是遇到运行时错误438对象不支持此属性或方法.我猜这是在告诉我重写'='运算符以测试两个对象的所有字段是否具有相同的值.但是我想要测试它们是否是同一对象.
But get a runtime error 438 object doesn't support this property or method. I'm guessing that's telling me to override the '=' operator to test if all the fields of the two objects have the same value. But what I want is to test whether they are the same object.
我猜这是在告诉我重写'='运算符以测试两个对象的所有字段是否具有相同的值.
I'm guessing that's telling me to override the '=' operator to test if all the fields of the two objects have the same value.
否,它告诉您对象没有默认属性,否则将调用该默认属性,并比较返回的结果.
No, it tells you the objects don't have a default property which would have been called otherwise, and the returned results compared.
您可以使用Is
If myObject Is yourObject Then