uh ok... first thing I noticed you might want to check... when you write: int INTow=INThw+INTaw; You assign it a value... when you increment INThw later, it won't change the value of INTow... I'm not sure if that's what you want... and the error you get is probably because there are non numeric characters in the textboxes... According to MSDN, when this occurs, it throws a FormatException So you'd have to use a try catch block to handle invalid values. Either one block for each .Parse() method and handle each value individually, or one single block for every values that would give an error like 'One or more invalid values' //One block for each
int INThw, INTht, INThl, INTaw,INTat, INTal; //You must declare your variables outside the block, or they would only be defined for that block
try
{
INThw=Int32.Parse(lblhw.Text);
}
catch (FormatException)
{
INThw = 0; //Or whatever value you want it to have in case of an invalid value
}
//Repeat for each //With a single try/catch block
int INThw, INTht, INThl, INTaw,INTat, INTal; //You must declare your variables outside the block, or they would only be defined for that block
try
{
INThw=Int32.Parse(lblhw.Text);
INTht=Int32.Parse(lblht.Text);
INThl=Int32.Parse(lblhl.Text);
INTaw=Int32.Parse(lblaw.Text);
INTat=Int32.Parse(lblat.Text);
INTal=Int32.Parse(lblal.Text);
}
catch (FormatException e)
{
//handle error, could be a messagebox followed by "return;" for example, to simply get out of the method
//you can use e.Message to get the actual error message, if you want to put it in your messagebox
} In addition, you could also control what the user can type in the textbox directly, using the Textbox_change event... Everytime the content of the textbox would be changed, you'd remove all characters from it, except "0123456789" and maybe '-' if you might need negative numbers There are many ways to do that... Not sure if the string class has a built-in function for that