Results 1 to 3 of 3

Thread: Redimming a Multidim

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987

    Thumbs down Redimming a Multidim

    Alright here's my situation. I have a multidimensioned array
    of objects and I am trying to use Redim to redimension either
    group of elements (i.e. Redim Array(5, 10) or Redim Array(10, 5).
    However apparently you can only redimension one group at a time
    without using Erase on the entire array, and starting from scratch. So these are the steps I am going through to be able to
    redimension this array presently.

    - Create a temporary array the size of the original

    - Fill the temporary array with the values stored in the original

    - Erase the original array

    - Redimension the original array with the new bounds

    - Set all the elements of the original array (now redimensioned) to New

    - Copy all the values from the temporary array to the new original array.

    Is there a better more efficient way to do this or am I stuck with
    the current method?
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    By using Redim or Redim Preserve, you can only change the last dimmension of the array (not including the inital redim).
    So if you have the code like this:
    VB Code:
    1. Dim arr() As Integer
    2.  
    3. Redim arr(10, 5)
    4.  
    5.  
    6. 'you cannot redim it again for the first dimmension
    7. 'this will give you an error
    8. 'Redim Preserve arr(5, 10)
    9.  
    10.  
    11. 'this is the only way
    12. Redim Preserve arr(10, YourNewNumber)
    13.  
    14. 'The only way to achieve what you're asking is to erase the array and recreate it
    15. Erase arr
    16. Redim arr(YourNumber, YourNumber)

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Sorry in my initial post I should have said I was trying to use Redim Preserve. I was kinda curious if there was a way to accomplish this using the CopyMemory API but that seems dangerous to mess with.
    Last edited by YoungBuck; Dec 26th, 2001 at 04:53 PM.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

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