Weird Array Set/Copy problem-VBForums
Results 1 to 3 of 3

Thread: Weird Array Set/Copy problem

  1. #1

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,418

    Question 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.



  2. #2
    Addicted Member cheesebrother's Avatar
    Join Date
    Jul 2011
    Posts
    153

    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).
    Hooked for good.

  3. #3

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,418

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.