You must Sign In to post a response.
  • Category: ASP.NET

    Dynamic 2-D array in vb.net

    hi
    how to increase no of rows in array..or create dynamic array in vb.net...i hv 2-D array..but when i am increasing its no of rows..it is givin error.
    ReDim can only change rightmost dimension in vb.net
    ......what is the solution for this
  • #352207
    Hi

    We can change the size of an array after creating them. The ReDim statement assigns a completely new array object to the specified array variable. You use ReDim statement to change the number of elements in an array. The following lines of code demonstrate that. This code reinitializes the Test array declared above.

    Dim Test(10) as Integer
    ReDim Test(25) as Integer
    'Reinitializing the array


    When using the Redim statement all the data contained in the array is lost. If you want to preserve existing data when reinitializing an array then you should use the Preserve keyword which looks like this:

    Dim Test() as Integer={1,3,5}
    'declares an array an initializes it with three members
    ReDim Preserve Test(25)
    'resizes the array and retains the the data in elements 0 to 2


    Thanks & Regards!
    Syed Shakeer Hussain


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.