I'm new to C#. I thought I knew a bit of C# but clearly not.
I'm trying to communicate with an Arduino using a C# Windows Form via the serial communication, when the button3 is clicked, the Windows Form app will send a command, for the Arduino to send back the required data, for the Windows Form app to fill in the specified Textboxes, but I'm getting Error CS0103 The name 'tb' does not exist in the current context
error.
I have tried all possible options provided but with no luck. This is the my code:
private void button3_Click(object sender, EventArgs e)
{
TextBox[] myTextBoxes = new TextBox[] { textBox9, textBox10, textBox11, textBox12, textBox13, textBox14, textBox15, textBox16 };
String[] myCommands = new String[] { "#TRMMH1\n", "#TRMMM1\n", "#TRMMH2\n", "#TRMMM2\n", "#TRMMH3\n", "#TRMMM3\n", "#TRMMH4\n", "#TRMMM4\n" };
String inString;
foreach (String co in myTextBoxes.SelectMany(tb => myCommands))
{
port.Write(co);
inString = port.ReadLine();
tb.Text = inString;
}
I have tried to search Google and Stack Overflow, but I'm not sure what to search for.