View Full Version : Solved: Redim Preserve Multi Dimensional dynamic Array
burtburt
04-24-2008, 07:26 PM
I have been trying to preserve data in a multidimensional dynamic array and it fails. runtime 9. using excel 2003 on thinkpad T61P
Sub test()
Dim testarry() As Integer
ReDim testarry(2, 2)
testarry(0, 0) = 1
testarry(0, 1) = 2
testarry(1, 0) = 3
testarry(1, 1) = 4
ReDim Preserve testarry(3, 2)
testarry(2, 0) = 5
MsgBox testarry(0, 0)
End Sub
burtburt
04-24-2008, 07:32 PM
crap. help is pretty good:
If you use the Preserve keyword, you can resize only the last array dimension and you can't change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array. The following example shows how you can increase the size of the last dimension of a dynamic array without erasing any existing data contained in the array.
ReDim X(10, 10, 10)
. . .
ReDim Preserve X(10, 10, 15)
fumei
04-25-2008, 11:30 AM
"crap. help is pretty good:"
Thanks burtburt. Also thanks for posting your follow up.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.