CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 1999
    Location
    usa
    Posts
    4

    how to increase dimension of n array

    how to increase dimension of an array by a set number of variable?
    for example i have an array

    dim co(n) as double

    where n is a user defined number.
    and every time i do certain operation on
    array co(n), i want that its dimension sould increase by same "n" number.




  2. #2
    Join Date
    Mar 2000
    Location
    Arizona, USA
    Posts
    493

    Re: how to increase dimension of n array

    Use The ReDim Statement:

    Dim TestArray() as Double
    Dim ArraySize as integer

    'Variable to Determine The Size Of The Array
    ArraySize = 10

    'Dimension The Array to A Variable Value
    Redim Preserve TestArray(ArraySize)




    The Preserve keyword saves all data already in the array. If you don't want to save the data
    dimesion the array as follows:

    Redim TestArray(ArraySize)




    Hope This Helps


    Kris
    Software Engineer
    Phoenix, AZ USA

  3. #3
    Join Date
    Apr 2001
    Location
    CA
    Posts
    153

    Re: how to increase dimension of n array

    Looks like a great suggestion. Only thing I would change is use 2 variables for maintaining size. One could be Arraysize and the other ArrayIncrease. Then you could do:

    ArraySize = ArraySize + ArrayIncrease
    Redim Preserve TestArray(ArraySize)



    each time you need to get a little bigger.

    thanx/good luck,
    adam
    thanx/good luck

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

Featured