Results 1 to 3 of 3

Thread: [RESOLVED] Problem with Redim Preserve

  1. #1

    Thread Starter
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Resolved [RESOLVED] Problem with Redim Preserve

    I'm getting a "Subscript out of range (Error 9)" on the 3rd line in the attached code.
    The ReDim Preserve is in a loop where I need to add incremental rows to the array, the width will always stay constant at 10.

    Any ideas what I'm doing wrong? (I know I've gotten this to work before, but can't see what I've done differently here)

    Note: Option Base = 1

    VB Code:
    1. Dim MyArray() As Integer
    2.  
    3.  
    4.  
    5. 'Later
    6. ReDim MyArray(1, 10)
    7.  
    8.  
    9. 'Later still
    10. ReDim Preserve MyArray(UBound(MyArray, 1) + 1, 10)
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Problem with Redim Preserve

    Using an multi-dimensional array, you're only allowed to change the last dimension!
    Allowed:
    VB Code:
    1. Dim MyArray() As Integer
    2. .
    3. .
    4. ReDim MyArray(1, 10)
    5. .
    6. .
    7. ReDim Preserve MyArray(1,UBound(MyArray, 1) + 1)
    NOT Allowed:
    VB Code:
    1. Dim MyArray() As Integer
    2. .
    3. .
    4. ReDim MyArray(1, 10)
    5. .
    6. .
    7. ReDim Preserve MyArray(UBound(MyArray, 1) + 1,10)
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Problem with Redim Preserve

    Thanks, I knew it was something stupid I was doing.

    VB Code:
    1. With DKenny
    2.     If .HoursAsleep < 3 Then
    3.         .Brain = False
    4.     End If
    5. End With
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

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



Click Here to Expand Forum to Full Width