I'm looking for a way to generate a "clone" of an object. Right now I need
to write a Clone function for every class that make and I'd like to have a
generic routine.
Instead of doing this:
For i = 0 to Me.Count-1
Set obj = New cSkill
obj.ID = Me.Item(i).ID
obj.Desc = Me.Item(i).Desc
obj.... etc.
Next
I'd like to do something like:
For i = 0 to Me.Count-1
Set obj = New cSkill
For j = 0 to number of properties
obj.property(j) = Me.Item(i).property(j)
Next
Next
Two problems... Is there a "property" property on objects? In my loop I
could be copying a simple variable or another object, so how do I know when
to say A=B or Set A=B.Clone ???
Here is my current clone function. This one is an array containing Skill
objects:
Public Function Clone()
Dim i 'General Counter
Dim objColl 'A new instance of our collection
Dim obj 'A single skill object used to copy
Set objColl = New cSkills
If Me.Count>0 then
Set Clone = New cSkills
For i=lBound(vCollection) To uBound(vCollection)
'Create a new Skill object
Set obj = New cSkill
obj.ID = Me.Item(i).ID
obj.Desc = Me.Item(i).Desc
Clone.Add obj
Next
End If
'Destroy temporary objects
Set obj = Nothing
End Function