Glad I could help!
Seriously it's good that you figured out a way around this and the way you found is a fairly subtle but powerful method. You can compose format strings in code, concatenating all sorts of stuff together, and then use them to format stuff. You can even do it with the more complicated formats you get when using String.Format.
As for your original question about why the code couldn't find dpoint, it's because you declared it inside { brackets }. That means it only exists within those brackets and disappears with the closing bracket.
Code:
if (decimalSelectToolStripMenuItem.Text == "0")
{
string dpoint = "F0";
}
else if (decimalSelectToolStripMenuItem.Text == "1")
{
string dpoint = "F1";
}
else if (decimalSelectToolStripMenuItem.Text=="2")
{
string dpoint="F2";
}
For example, is the menu item's Text is 2, then the last section executes, creates a variable named dpoint, sets it equal to F2, and then exits so dpoint goes out of scope and disappears.
In the following version the variable is declared outside of the if-then statements so it still exists when they end.
Code:
string dpoint = "F0";
if (decimalSelectToolStripMenuItem.Text == "0")
{
dpoint = "F0";
}
else if (decimalSelectToolStripMenuItem.Text == "1")
{
dpoint = "F1";
}
else if (decimalSelectToolStripMenuItem.Text=="2")
{
dpoint="F2";
}
Now the following code can use dpoint.