Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
802 views
in Technique[技术] by (71.8m points)

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

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...