Hello guys im having problem displaying a math equation result in the textbox. It shows 0 and i dont really know where i got the error.
Name of the textbox where result shall be displayed is total1
Thx for help :)

        int textboxnumber1;
        int textboxnumber2;
        int textboxnumber3;
        int textboxnumber4;

        textboxnumber1 = int.Parse(textBox7.Text);
        textboxnumber2 = int.Parse(textBox10.Text);
        textboxnumber3 = int.Parse(textBox18.Text);
        textboxnumber4 = int.Parse(textBox34.Text);

        int answer1 = 0;
        answer1 = textboxnumber1 + textboxnumber2 + textboxnumber3 + textboxnumber4;
        total1.Text = answer1.ToString();

edit: My frist post was actually an answer lol...

original post meant to be

int answer1 = 0;
total1.Text = answer1.ToString();
answer1 = textboxnumber1 + textboxnumber2 + textboxnumber3 + textboxnumber4;

and answer is

int answer1 = 0;
answer1 = textboxnumber1 + textboxnumber2 + textboxnumber3 + textboxnumber4;
total1.Text = answer1.ToString();
.
which is original post....

So two last lines needed to be changed around. now it stores and it seem to work :)
Solved.

Well this works fine to me. I have added two other ways you can do this thing. Here is the code.

int answer = 0;

int num1 = int.Parse(textBox1.Text);
int num2 = int.Parse(textBox2.Text);
int num3 = int.Parse(textBox3.Text);
int num4 = int.Parse(textBox4.Text);

answer = num1 + num2 + num3 + num4;
MessageBox.Show(answer.ToString());

int num5 = Int32.Parse(textBox1.Text);  // OR:   Convert.ToInt32(textBox1.Text);
int num6 = Int32.Parse(textBox2.Text);  // OR:   Convert.ToInt32(textBox2.Text);
int num7 = Int32.Parse(textBox3.Text);  // OR:   Convert.ToInt32(textBox3.Text);
int num8 = Int32.Parse(textBox4.Text);  // OR:   Convert.ToInt32(textBox4.Text);

answer = num5 + num6 + num7 + num8;
MessageBox.Show(answer.ToString());

They all work fine.

This question has already been answered. Start a new discussion instead.