Unassigned Varibles?

privatevoid menuItem15_Click(object sender, System.EventArgs e)

{

MenuItem mnuItem = (MenuItem) sender;

mnuItem.Checked = !mnuItem.Checked;

FontStyle fsStyle;

switch (mnuItem.Text.Replace("&",""))

{

case "Bold":

fsStyle = FontStyle.Bold;

break;

case "Italic":

fsStyle = FontStyle.Italic;

break;

case "UnderLine":

fsStyle = FontStyle.Regular;

break;

}

rtbText.SelectionFont =new Font(rtbText.SelectionFont.FontFamily,

rtbText.SelectionFont.Size,

rtbText.SelectionFont.Style^fsStyle);

I getting the error saying my fsStyle is not assigned? Why is that i thought i assigned them to the bold italic, and underline types

[1857 byte] By [Dpowers] at [2007-12-16]
# 1
In every one case you have to set variable, you forgot to default case :)
gibic at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 2
And also, your fsStyle is not defaulted to any value. Therefore if the switch isn't true for any of the case, it'll not be assigned.

If it's a compiler error (sorry can't remember off-hand but it should be a compiler error stating no default value set to fsStyle), you have to assign your fsStyle to something.

Best bet is to assign your fsStyle to a default value.

JustinLee at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...