Results 1 to 5 of 5

Thread: Resizing multi-dimensioned array

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 1999
    Posts
    51

    Post

    I can't get this to work. I need to dynamically add to a two dimension array. Where am I going wrong? It goes through a loop and the second time it adds a column it give me a subscript out of range.

    Thanks
    Code:
    Dim sDocInfo() As String
    Dim iDocInfo As Integer
    
    ReDim Preserve aDocInfo(iDocInfo, 2)
    aDocInfo(iDocInfo, 1) = "info"
    aDocInfo(iDocInfo, 2) = "info2"
    iDocInfo = iDocInfo + 1

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    You can resize only last dimantion of your array.

    Example:

    Code:
    Dim arrMyArray()
    
    Redim Preserve arrMyArray(5, 2)
    Redim Preserve arrMyArray(5, 10)  'This will add 8 more elements
    ------------------

    Serge

    Senior Programmer Analyst
    [email protected]
    [email protected]
    ICQ#: 51055819

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 1999
    Posts
    51

    Post

    Thanks Serge.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Let me modify what Serge said a little. You can only resize the last dimension of your array when you specify Preserve. If you remove Preserve your code would not give you an error, but that may not be what you want to do,

    ------------------
    Marty
    HASTE CUISINE
    Fast French food.

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Post

    That's right!

    Because of this I had to use a 1D-array for my map (tile-based game) so I could resize it.
    (You just have to calculate the 'real' position in the array... not much work)

    ------------------
    [email protected]
    ...
    Every program can be reduced to one instruction which doesn't work.


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