Using VS2010 Express, C# and it’s WinForms Application.
Here I have three text boxes(aTextBox, bTextBox, cTextBox) from which Inputs are strings and then using int.Parse(aTextBox.Text) converted to integers.
Then a Button (calcBtn) method which is going to calculate charges and then to display results after some maths to particular TextBoxes on Result groupBox which again contains text boxes for results…
The problem is causing by the way I am parsing or the order in which it’s executing. If any of the textbox is filled then result should display and not to get in the format exceptions. Here I am getting stuck because inside the calcBtn I am parsing all text boxes and if one of them is empty then exception occurs. Compiler is I guess trying to parse empty strings from the empty text boxes, and I don’t want it to be.
Any suggestions if you got what I mean? 🙂
Here’s what GUI looks like

The
Int32.Parsemethod does not accept malformed strings, and this includes empty strings. I have two suggestions.You could check if the string is empty/whitespace first, and return 0 or some other default value:
Or you could simply ignore all parsing errors, treating them as 0. This will treat things like
"","123abc", and"foobar"as zero.Which approach you take depends on the specific needs of your application.