Consulting

Results 1 to 3 of 3

Thread: Solved: Redim Preserve Multi Dimensional dynamic Array

  1. #1
    VBAX Regular
    Joined
    Mar 2008
    Posts
    37
    Location

    Solved: Redim Preserve Multi Dimensional dynamic Array

    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

  2. #2
    VBAX Regular
    Joined
    Mar 2008
    Posts
    37
    Location
    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)

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "crap. help is pretty good:"

    Thanks burtburt. Also thanks for posting your follow up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •