PDA

View Full Version : Class Deep Copy



samkhalilian
10-06-2010, 06:57 AM
In VBA how do I copy a class object e.g.

Dim A MyClass, B MyClass
Set A=New MyClass
Set B=A

The above will make B point to A. But I need B to be a copy of A?

Cheers, Sam

Bob Phillips
10-06-2010, 07:59 AM
Why would you need a copy, a pointer is more efficient.

samkhalilian
10-06-2010, 09:00 AM
Sometimes you need to make a copy. I dont want to change object A when I change object B.

Ergo I need a deep copy! Does VBA have this functionality?

A clone function perhaps?

Bob Phillips
10-06-2010, 09:13 AM
There is nothing in VBA that I know of to do this, so you would have to write your own clone method.