Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Having some trouble with my equals button

this is the first real program I’m making for school, and I’m having some trouble with it. I believe my case structure and everything else is right, but when I attempt to add two numbers in my calculator, the text property for label 7 does not update.

This is my sample of how I have my case structure set up:

    private void radioButton5_CheckedChanged(object sender, EventArgs e)
    {
        if (radioButton5.Checked == true)
            rb = 5;
    }

and then the actual case structure itself, as well as the rest of the code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    public void button1_Click(object sender, EventArgs e)
    {
        double num1 = 0;
        double num2 = 0;
        double result = 0;
        string resultInLabel;

        switch (rb)
        {
            case 1:
                result = num1 + num2;
                break;
            case 2:
                result = num1 - num2;
                break;
            case 3:
                result = num1 * num2;
                break;
            case 4:
                result = num1 / num2;
                break;
            case 5:
                break;
        }
        resultInLabel = Convert.ToString(result);
        resultInLabel = label7.Text;
    }

button1 is my equals button, forgot to rename it. If more code is needed please let me know, first time posting and unsure how much more context is needed. Thanks for any answers.

>Solution :

If you want to change the text of the label you have to assign a value to it, not read its current value. Make your last line the following:

label7.Text = resultInLabel;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading