-
Mar 11th, 2012, 09:24 AM
#1
Thread Starter
Frenzied Member
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?
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.
-
Mar 11th, 2012, 09:54 AM
#2
Addicted Member
Re: Weird Array Set/Copy problem
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).
-
Mar 11th, 2012, 01:44 PM
#3
Thread Starter
Frenzied Member
Re: Weird Array Set/Copy problem
good link.. seems to do the trick...
thanks
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|