I'm trying to set a variable to a color by using a switch statement to evaluate a string. Here's the code: private void DrawBarChart(Graphics g, String theYear, String theOption, String theBG, String theBar) { Color clrBack = Color.LightYellow; Color clrBar
= Color.Red; Switch(theBG) { case("LightYellow"): clrBack = Color.LightYellow; break; case("White"): clrBack = Color.White; break; case("LightGray"): clrBack = Color.LightGray; break; default: clrBack = Color.LightYellow; break; } Switch(theBar) { case("Red"):
clrBar = Color.Red; break; case("Blue"): clrBar = Color.Blue; break; case("Green"): clrBar = Color.Green; break; case("Purple"): clrBar = Color.Purple; break; default: clrBar = Color.Red; break; } If I comment out the switch statements the code will run with
the default values defined at the beginning. I don't see what is wrong. Anyone have an idea?
Hawkeye3677
Member
10 Points
2 Posts
Setting variable with switch stmt
Dec 11, 2003 02:49 PM|LINK