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();

Have you stepped through this in the debugger to see if the individual variables are being set?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.