So… I have this section of code here, everything seems perfect but when I try to run this, it gives a formatting exception handler error.
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text != null)
{
minusTime = Convert.ToInt32(textBox1.Text); // fix this... idk what's even wrong. Just trying to assign user input to minusTime...
}
else
{
minusTime = 0;
}
}
*Note: textbox1 is user input of an integer value. minusTime is a null integer that is to be assigned to the user input.
I’ve tried running this with just “Convert.ToInt32(textBox1.Text)” but it still gives me an exception saying the user inputted a wrong format… when the user input is clearly an int.
You want
This will cope if the input isn’t an integer returning
false.MSDN page
There is another overload that takes in more information about the possible format of the number:
This will cope with currency symbols etc.