PDA

View Full Version : Solved: Multidimensional array



arm
03-19-2009, 01:23 AM
Hi,

Is it possible to preserve values in multidimensional array where first value is dynamic?

-> ReDim Preserve MyArray("dynamic",10)

If it's not possible, is there any simple way to copy values from old array to new array and back to dynamically changed array
( for example MyArray(1,10) -> Myarray(2,10) )? And how?

Thanks!

arm

Nelviticus
03-19-2009, 07:33 AM
You can get the size of an array's dimensions with UBound - UBound(MyArray, 1) will give you the current size of the 1st dimension, UBound(MyArray, 2) will give the size of the 2nd and so on. You could use those sizes to create a new, larger array then use nested loops to copy the elements to the new array. Then ReDim your old one and use nested loops to copy the elements back again.

If you could re-work your code to make the second dimension the dynamic one, rather than the first, you could use ReDim Preserve to re-size it.

Regards

arm
03-20-2009, 05:27 AM
Nelviticus, thanks for help!

This problem is solved now.

arm

Paul_Hossler
03-23-2009, 12:57 PM
don't forget to mark it 'Solved" using Tread Tools

PH