Windows Forms Program Question

ok, here is the relevant code. The goal is to take the input, convert it to a number variable, do some math on it and, send that info back to the form. It works so far as when you enter a number in the text box, the program converts it to an int, adds 10 and sends it to the form. The issue is if you enter a number and then backspace until there is nothing in the text box, it throws an error.

My guess is that it is because 'null' is not something that can be converted to an int. Would the solution be to add an if statement that checks for the null character and sets the foo variable to 0?

Thanks for your suggestions.

1
2
3
4
5
6
7
8
9
10
11
private: System::Void HealthTextBox_TextChanged(System::Object^  sender, System::EventArgs^  e) {

				 double foo = System::Convert::ToDouble(HealthTextBox->Text);

				 foo += 10;

				 String^ test = Convert::ToString(foo);

				 healthLabel2->Text = test;

			 }
Try trim and try/catch. I can post some code if u need
Topic archived. No new replies allowed.