Setting variable with switch stmthttp://forums.asp.net/t/415993.aspx/1?Setting+variable+with+switch+stmtMon, 15 Dec 2003 15:52:57 -0500415993415993http://forums.asp.net/p/415993/415993.aspx/1?Setting+variable+with+switch+stmtSetting variable with switch stmt 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? 2003-12-11T14:49:10-05:00416116http://forums.asp.net/p/415993/416116.aspx/1?Re+Setting+variable+with+switch+stmtRe: Setting variable with switch stmt I figured it out...I was using Switch vs switch. I put the code in VS.Net and figured it out. switch(theBG) { case "LightYellow": ... case "White": ... default: ... } 2003-12-11T16:49:14-05:00418836http://forums.asp.net/p/415993/418836.aspx/1?Re+Setting+variable+with+switch+stmtRe: Setting variable with switch stmt Try this it is much cleaner. Color clrBack; try { clrBack = (Color)Color.FromName(theBG); } catch (Exception) { ... Do Default Stuff Here ... } This will work for any color that is listed in the Color Struct 2003-12-15T15:34:20-05:00