Go Down

Topic: problem on case in switch statement in C# (Read 1 time) previous topic - next topic

arduino_learners

hi everyone...would like to seek ur help in solving my problem..i have a problem of getting the warning sign...in addition, there an error stated that " control cannot fall through from one case label into another..im using c# language with visual basic 2010 ultimate software..
im also want to put the sign in serial..which means..when the transmitter sends the value of the voltage; the sign will appears accordingly.should i put the for statement for serial data?
tq

Code: [Select]
switch (waterlevel)
                {
                    case "SAFE":
                        if (voltage >= 0.0 || voltage <= 0.50)
                        {
                            label_result.Text = " SAFE";
                            label_result.ForeColor = Color.Green;
                            break;
                        }


                    case "WARNING":
                        if (voltage >= 0.50 || voltage <= 0.60)
                        {
                            label_result.Text = " WARNING";
                            label_result.ForeColor = Color.Yellow;
                            break;
                        }

                    case "DANGER":
                        if (voltage >= 0.60 || voltage <= 0.70)
                        {
                            label_result.Text = " DANGER";
                            label_result.ForeColor = Color.Red;
                            break;
                        }
                    default:
                        label_result.Text = "invalid";
                        break;

                }

AWOL

Code: [Select]
switch (waterlevel)
                {
                    case "SAFE":

Lose the string.
switch/case doesn't work with strings (or Strings).
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

Quote
im using c# language with visual basic 2010

You most assuredly are not. You may be using C# with Visual Studio, but not to program the Arduino.

AWOL

Quote
control cannot fall through from one case label into another

In C# that is true, but not in C/C++.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

arduino_learners

ok.AWOL...im declaring the water level as string...can u help me to debug my code?tq

Paul: yeah..this is visual studio 2010 ultimate..sorry for the mistakes..

AWOL

Sorry, no, I don't know any I-can't-believe-it's-not-Java C#
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

Move the break statement outside the if body. The break should not be conditional.

arduino_learners

thanks Paul for the help..i have rectified the problem..

Go Up