Weird Array Set/Copy problem
Hello,
The scenario is this:
Presuming I have an array of a CLASS of 30 kids and each child has sub properties, age, height etc...
So:
Private tmpChildNo() As New clsKids 'Array to 30 kids, being reDimmed later on
Private tmpCopy As New clsKids 'Tmp Variable for a SINGLE CHILD
When I try and copy say the position of Child 2 (tmpCopy) to tmpChildNo(Child 5), for e.g:
Set tmpCopy = tmpChildNo(2)
tmpcopy.newNo = 5 'Update position of 2 to 5
Set tmpChildNo(5) = tmpCopy
Now the problem is that both tmpChildNo(2).newNo & tmpChildNo(5).newNo have been changed to the same thing?
As if it has passed the array with REFERENCE rather than just ByVal ?
Why are both arrays affected?
Re: Weird Array Set/Copy problem
Quote:
As if it has passed the array with REFERENCE rather than just ByVal ?
Yes, that's the way classes work. To copy your class you could make a clone function. See what si_the_geek told me when i asked how to copy a class. (link).
Re: Weird Array Set/Copy problem
good link.. seems to do the trick...
thanks