VBA: how to test for object equality (whether two variables reference the same object)

前端 未结 2 1903
悲&欢浪女
悲&欢浪女 2020-12-06 05:20

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          


        
2条回答
  •  感动是毒
    2020-12-06 05:48

    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.

    You test reference equality with Is

    If myObject Is yourObject Then 
    

提交回复
热议问题