|
-
Dec 26th, 2001, 04:35 PM
#1
Thread Starter
Fanatic Member
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}
-
Dec 26th, 2001, 04:41 PM
#2
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:
Dim arr() As Integer
Redim arr(10, 5)
'you cannot redim it again for the first dimmension
'this will give you an error
'Redim Preserve arr(5, 10)
'this is the only way
Redim Preserve arr(10, YourNewNumber)
'The only way to achieve what you're asking is to erase the array and recreate it
Erase arr
Redim arr(YourNumber, YourNumber)
-
Dec 26th, 2001, 04:50 PM
#3
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|