I have this code that it works only if all the textBox contains values.. But if a textbox is empty i get an error..
Int32 Total = Int32.Parse((txtChild1.Text))
+ Int32.Parse(txtChild2.Text)
+ Int32.Parse(txtChild3.Text)
+ Int32.Parse(txtWife1.Text)
+ Int32.Parse(txtWife2.Text)
+ Int32.Parse(txtWife3.Text);
I know that it must be a function like IsNull but for the integer values..
Does anyone know what it is ?
You can use
Int32.TryParse:TryParsewill try to parse the text and if it fails, it will set the variable to 0.You can also inline some of the logic (although this makes the code very long and messy):
Int32.TryParsereference: http://msdn.microsoft.com/en-us/library/f02979c7.aspxShorthand if reference: http://msdn.microsoft.com/en-gb/library/ty67wk28(v=vs.110).aspx