Pages: [1]   Go Down
Author Topic: problem on case in switch statement in C#  (Read 1238 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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;

                }
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26322
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
switch (waterlevel)
                {
                    case "SAFE":
Lose the string.
switch/case doesn't work with strings (or Strings).
Logged

"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.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49372
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26322
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
control cannot fall through from one case label into another
In C# that is true, but not in C/C++.
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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..
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26322
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, no, I don't know any I-can't-believe-it's-not-Java C#
Logged

"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.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49372
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: