Input String
-
Hi, I have the following code private void checkBox2_CheckedChanged(object sender, System.EventArgs e) { if(checktables.Checked == true) { int tables = Convert.ToInt32(txtqtables.Text); listBox1.Items.Add(35 * tables); } } If I click on my CheckBox, I want the number in the txtqtables.text to be multiplied by 35 and the results to be place in a listbox. I am getting an error on "int tables = Convert.ToInt32(txtqtables.Text);" Input string is not in a correct format. Please help.
-
Hi, I have the following code private void checkBox2_CheckedChanged(object sender, System.EventArgs e) { if(checktables.Checked == true) { int tables = Convert.ToInt32(txtqtables.Text); listBox1.Items.Add(35 * tables); } } If I click on my CheckBox, I want the number in the txtqtables.text to be multiplied by 35 and the results to be place in a listbox. I am getting an error on "int tables = Convert.ToInt32(txtqtables.Text);" Input string is not in a correct format. Please help.
paullet wrote:
I am getting an error on "int tables = Convert.ToInt32(txtqtables.Text);" Input string is not in a correct format.
Then the value that is put in the text box is not an integer. You need to validate the contents of the text box first, then attempt to convert it. You can also use Int32.TryParse to attempt to convert it and return a boolean to indicate if the conversion succeeded.
Upcoming FREE developer events: * Glasgow: Agile in the Enterprise Vs. ISVs, db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website
-
Hi, I have the following code private void checkBox2_CheckedChanged(object sender, System.EventArgs e) { if(checktables.Checked == true) { int tables = Convert.ToInt32(txtqtables.Text); listBox1.Items.Add(35 * tables); } } If I click on my CheckBox, I want the number in the txtqtables.text to be multiplied by 35 and the results to be place in a listbox. I am getting an error on "int tables = Convert.ToInt32(txtqtables.Text);" Input string is not in a correct format. Please help.
Hi, if TextBox is empty or contains something that Convert does not recognize you would get that exception.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google