I’m trying to make a loop to check if certain files exist, and if they do they’re going to change an indicator label on my form, but I can’t seem to work out how to do this w/out typing out every single one manually such as this:
if (File.Exists("C:\\MonitorFiles\\BOT-PC-8is1.txt"))
{
PC8IS1.BackColor = Color.Green;
}
if (File.Exists("C:\\MonitorFiles\\BOT-PC-8is2.txt"))
{
PC8IS2.BackColor = Color.Green;
}
if (File.Exists("C:\\MonitorFiles\\BOT-PC-8is3.txt"))
{
PC8IS3.BackColor = Color.Green;
}
I’ve tried several very basic ways of just building arrays and substituting but I can’t put ” VariableX.backcolor “, I’ve tried [variable].backcolor, no dice.
This is a hard one to search for on google, and hopefully has an easy answer!
Thanks
What you want is a dictionary, the key will be the file-name the value will be your control.