Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8768503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:05:05+00:00 2026-06-13T17:05:05+00:00

I am trying to increase the x value of the 2 dimensional array but

  • 0

I am trying to increase the x value of the 2 dimensional array but I keep receiving this error.

'ReDim' can only change the rightmost dimension

I need to do this while maintaining the data of the array. Here is my code.

            Dim x As Integer = 0
            Dim y As Integer = 0
            While reader.Read()
                ReDim Preserve catagoryInfo(x, 2)
                catagoryInfo(x, y) = reader.GetString(0)
                y += 1
                catagoryInfo(x, y) = reader.GetString(1)
                x += 1
                y = 0
            End While
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:05:07+00:00Added an answer on June 13, 2026 at 5:05 pm

    In a multidimensional array, you can change only the last dimension when you use Preserve. If you attempt to change any of the other dimensions, a run-time error occurs.
    A part from this your code is really suboptimal because you are planning to Redim you array at every loop. Redimming with preserve is worse because not only the runtime allocates a new array but it should also copy from the old array to the new array.

    In your case is better to declare a simple class like this

    Public Class CategoryInfo
        Public info1 As String
        Public info2 As String
    End Class
    

    then use a List(Of CategoryInfo)

    Dim infos as List(Of CategoryInfo) = new List(Of CategoryInfo)()
    While reader.Read()
        Dim nf As CategoryInfo = new CategoryInfo() 
        nf.info1 = reader.GetString(0)
        nf.info2 = reader.GetString(1)
        infos.Add(nf)
        ' if you like the all-in-one-line coding style you could also write the above in this way
        ' infos.Add(New CategoryInfo With {.info1=reader.GetString(0), .info2=reader.GetString(1)} )
    End While
    

    Now, if you really need to have your data inside a string array you could write

    Dim categoryInfo(infos.Count, 2) as String
    for x = 0 to infos.Count -1
        categoryInfo(x,0) = infos(x).info1
        categoryInfo(x,1) = infos(x).info2
    next
    

    this is still not very optimal because you loop two times on your data but, at least, it will get your data as you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to increase or decrease the displayed texts font. but can only
I am trying to increase a variable's value while uibutton is kept pressing. But
I have this AJAX loader, created using CSS. And I m trying to increase
What im trying to accomplish is to increase create and increase a value in
I'm trying to allocate memory for a array of structures, but after it is
I am trying to increase/decrease Max and Min value of Y axis in a
I am trying to write a migration that will increase the value of an
I'm trying to achieve a dynamic two dimensional array in C. Whenever the program
I'm trying to decrease or increase the value in a textbox using javascript. I
I am trying to increase the size of my 2D array and hm is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.