I am pretty new to C#, I have been searching for an hour or so now for what I need and can't find it. I am trying to look at the contents of 32 different text box's using for loops. The code I have at the moment is:
    private void btnCalculate_Click(object sender, EventArgs e)
    {
        string ElementString;
        Control ElementControl;
        double Num;
        Boolean errorMsg = false;
        for (int x = 1; x <= 4; x++)
            for (int y = 1; y <= 4; y++)
            {
                ElementString = "txtA" + x.ToString() + y.ToString();
                ElementControl = this.Controls[ElementString];
                ElementString = ElementControl.Text.Trim();
                if (!double.TryParse(ElementString, out Num))
                {
                    errorMsg = true;
                    break;
                }
            }
        if (errorMsg)
            MessageBox.Show("Error Processing Input Matricies, invalid entries");
    }
Ok changing this part, sorry for not putting more information, but hopefully this will help.
The program crashes when the button is clicked. It crashes when running the line:
ElementString = ElementControl.Text.Trim();
And gives the error message:
Object reference not set to an instance of an object.
Thank you
 
     
    