Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to join two multidimensional array
#1
i have 2 multiminesional arrays..

how to join them into one..
Reply
#2
Get the Count of Second Array. Redim He first Array with the Second Array count and loop through the Second Array and append all the values of Second Array to first Array.

let me know if you want code snippet also.
Reply
#3

can u provide syntax..
Reply
#4
Redim will erase all the existing elements from the array, and Redim Preserve does not work on 2-D(or multidimensional array).

Venkatesh, you can first resize the array keeping the old elements intact and then you can assign the value of the 2nd array to first.

I have written the following function which can be used as Redim Preserve on 2-D array.
Code:
'function to increase the size of Array "arr" 'newubound_1 = new no of rows 'newubound_2= new no. of columns Function ArrayPreserve(arr,newubound_1,newubound_2) 'retrieve the existing dimensions of the array oldubound_1 = CInt(UBound(arr,1)) oldubound_2 = CInt(UBound(arr,2)) 'Create a new array of the same dimension ReDim arr_new (oldubound_1,oldubound_2) 'copy the original array to the new array For i = 0 To oldubound_1 For j = 0 To oldubound_2 arr_new(i,j) = arr(i,j) Next Next 'resize the new array ReDim arr(newubound_1,newubound_2) 'copy the new array back to Original resized array For i = 0 To oldubound_1 For j = 0 To oldubound_2 arr(i,j) = arr_new(i,j) Next Next ' erase the arr_new Erase arr_new End Function

you can make the function robust by using conditions that would check that the new dimension is more than the previous dimension.
Tweak the code and apply logic. you should get it !!
Reply
#5
Thank you buddy
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort multidimensional array SBsteven 8 10,303 03-14-2014, 02:49 PM
Last Post: anuj.bajaj
  How to convert a single dimension array to two dimensional array venkatesh9032 3 6,427 02-10-2014, 03:07 PM
Last Post: pranikgarg
  Adding array to another Global array in VB Script test911 1 3,576 12-02-2012, 12:40 PM
Last Post: parminderdhiman84

Forum Jump:


Users browsing this thread: 1 Guest(s)