if else with checkbox and string

4.4k views Asked by At

could someone help me figure out what I am doing wrong. I have tried so many ways and can't get it to work in all cases at same time.

Our symbol devices have multiple firmware versions that cause issues with the wireless card in the device. if the firmware version is 86.09.0000 it will work fine. If the firmware version if anything else "01.09.000" it will cause issues so i have it dump a cab file with factory firmware and reboot device.

Thanks for help, below is working code.

if (checkBox1.Checked && myString == "86.09.0000")
        {

         //check box checked and correct string


        }
        else if ((checkBox1.Checked == false) && (myString == "86.09.0000"))
        {
         //check box not checked and correct string

        }
        else
            {
               // string doesn't match
            }
3

There are 3 answers

0
Chris On

I would assume you mean if myString isn't 86.09.0000... Is your final else in the wrong 'if' statement?

        if (checkBox1.Checked && myString == "86.09.0000")
        {

            wipefiles();

        }
        else if ((checkBox1.Checked == false) && (myString == "86.09.0000"))
        {
            if (myThread == null)
            {
                label4.Visible = false;
                pictureBox1.Enabled = false;
                SystemIdleTimerReset();
                menuItem1.Enabled = false;
                myThread = new Thread(MyWorkerThread);
                myThread.IsBackground = true;
                myThread.Start();
            }

        }
        else
            {
                MessageBox.Show("Install firmware");
            }

Is this possibly what you were trying to accomplish?

0
DonBoitnott On
Private void menuItem1_Click(object sender, EventArgs e)
{
    String oemVersion = oemver.getOEMVersion();
    String myVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

    if (myVersion.Equals(oemVersion))
    {
        if (checkBox1.Checked)
            wipefiles();
        else
        {
            if (myThread == null)
            {
                label4.Visible = false;
                pictureBox1.Enabled = false;
                SystemIdleTimerReset();
                menuItem1.Enabled = false;
                myThread = new Thread(MyWorkerThread);
                myThread.IsBackground = true;
                myThread.Start();
            }
        }
    }
    else
    {
        MessageBox.Show("Install firmware");
    }
}
1
AudioBubble On

Simply add another "OR" || condition in your if statement .See below

if (checkBox1.Checked && (myString == "86.09.0000"***||myString="01.09.000"***))
        {

            wipefiles();

        }
        else if ((checkBox1.Checked == false) && (myString == "86.09.0000"***||myString="01.09.000"***))
        {
            if (myThread == null)
            {
                label4.Visible = false;
                pictureBox1.Enabled = false;
                SystemIdleTimerReset();
                menuItem1.Enabled = false;
                myThread = new Thread(MyWorkerThread);
                myThread.IsBackground = true;
                myThread.Start();
            }

        }
        else
            {
                MessageBox.Show("Install firmware");
            }

Now It's working for you ! But it's not good .Because it's maay be going to lot of "OR" condition . So Please assign the mystring value from when code running!