to find the sum of textbox values ,i use this code
private void textBox10_TextChanged(object sender, EventArgs e)
{
int n1, n2, n3, n4, n5,sum;
n1 = Convert.ToInt32(textBox6.Text.ToString());
n2 = Convert.ToInt32(textBox7.Text.ToString());
n3 = Convert.ToInt32(textBox8.Text.ToString());
n4 = Convert.ToInt32(textBox9.Text.ToString());
n5 = Convert.ToInt32(textBox10.Text.ToString());
sum = n1 + n2 + n3 + n4 + n5;
// sum
textBox16.Text = Convert.ToString(sum);
}
Sam HobbsPosted Apr 15, 2011, 3:07 AM
Also, validate the data to ensure it is valid. You can use the Int32.TryParse Method instead of the Convert.ToInt32 Method to avoid errors that cause the program to fail and instead issue an error message to the user.
Suthish NairPosted Apr 14, 2011, 2:43 PM
CrishPosted Apr 13, 2011, 7:02 AM
or
Pass the sum this Formate
txt16=txt11+txt12+txt13+txt14+txt15;
Ankit NandekarPosted Apr 13, 2011, 3:20 AM
Vijay YadavPosted Apr 13, 2011, 3:08 AM
May be one of your textbox value getting null value or any other value rather than number. Check once again by giving all the textboxes a numerci value. It will work!! :)