4
Answers

Help with "Input string was not in a correct format" error

Riemann Harrison

Riemann Harrison

13y
3.5k
1
Hi, first of all, I wanna thank this helpful forum which seeks to aid those of us who are just getting started with the world of programming.

My problem is as fallows, I want to add elements to an array, for that, I created a textbox wich would add the elements to the array,my code is as fallows:


      
        int[] table = new int[24];
        private void btnInput_Click(object sender, EventArgs e)
        {
            int elem = 0;
            
            for (int i = 0; i < table.Length; i++)
            {
                if (i < table.Length)
                {
                    tabla[elem] = Convert.ToInt32(txtEntrada.Text);//Input string was not in a correct format
                    txtEntrada.Clear();
                }

                else if (i==tabla.Length)
                {
                    MessageBox.Show("Array full");
                }
            }
        }

How ever, I get a code error while debugging, it says that the input string was not in correct format, which I don't understand why since I converted to int32, can someone please guide me as how can I fix this issue?

Hope someone can help me out with this, many thanks.

Answers (4)