Results 1 to 7 of 7

Thread: [RESOLVED] Array to Array

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Resolved [RESOLVED] Array to Array

    Dim Array1(0 To 10) As Integer
    Dim Array2(0 To 10) As Integer

    Array2 = Array1

    Why can I not do this?

    I get Can't assign to array error


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Array to Array

    Just the way it is with static arrays. I imagine that the SafeArray structure that describes those arrays internally, includes the flag: FADF_FIXEDSIZE. That flag says that the array may not be resized or reallocated.

    No errors:
    Code:
    Dim Array1() As Integer
    Dim Array2() As Integer
    ReDim Array1(0 To 10) 
    ReDim Array2(0 To 10)
    Array2 = Array1
    Updated: Yep, just verified it. The SafeArray structure returned from such an array includes the flag to prevent resizing/reallocation.
    Last edited by LaVolpe; Sep 18th, 2014 at 11:15 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Array to Array

    If you make array2 dynamic you should be okay
    Code:
    Dim Array1(0 To 10) As Integer
    Dim Array2() As Integer
    Dim i As Integer
    
        For i = 0 To 10
            Array1(i) = (i + 1) ^ 2
        Next i
    
        Array2 = Array1
        
        For i = 0 To UBound(Array2)
            Debug.Print Array2(i)
        Next i

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Array to Array

    Thanks MT for the info however I have to use LaVolpe's way because later I am going to reverse the assignment

    Array1 = Array2


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Array to Array

    Thanks, LaVolpe, that's what I need.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Array to Array

    Quote Originally Posted by jmsrickland View Post
    Thanks, LaVolpe, that's what I need.
    You're welcome.

    Note that if both arrays will start with same values, just populate one & set the unpopulated one equal the populated one. Can save a line of code or more at times.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: [RESOLVED] Array to Array

    As with so many of these fundamental issues, this is covered in the VB6 documentation.

    See Advanced Features of Arrays.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width