Link to home
Start Free TrialLog in
Avatar of Rossamino
Rossamino

asked on

Two 2-dimensional arrays. Make one 2-dimensional array with a function? Visual Basic

If I've got arrData that's 20 by some large number and another array, arrNewData (also 20, by some number), how can I combine them into a single array?

I was thinking something like arrData = fCombineArrays(arrData,arrNewData), but would that work and what would the fCombineArrays function look like?
ASKER CERTIFIED SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
1. What data type are your arrays?
2. Do you have any control over the dimension-defining code?
Avatar of HooKooDooKu
HooKooDooKu

The only way to "combine" two arrays is to simple create a third array and copy everything from the two arrays to the third array.

If your arrays are ReDim able, you can always to a ReDim Preserve on the 1st array, sizing it to fit the data for both arrays.  That will create this third array, and copy the data from the 1st array, and free the memory of the old 1st array for you all with one command.  But "under-the-hood", you're still creating a third array and copying data to it... you're just letting the language do it for you.

Dim A1() as integer
Dim A2() as ineger
Dim I as integer

ReDim A1(20,20)
LoadA1( A1 )

ReDim A2(20,10)
LoadA2( A2 )

ReDim Preserve A1(20,30)
AppendA2ToEndOfA1
ReDim A2(-1 to -1)   'I liked doing this to 'flag' an array as empty

Open in new window