Greetings.

I'm getting the unhandled NullReferenceException error when I run the following code:

private void btnCalcMoonPhase_Click(object sender, EventArgs e)
{
MoonForm MF = new MoonForm();
DateTime dDate = Convert.ToDateTime(txtStartDate.Text);
string[] dtMoonDates = new string[10];

dDate = dDate.AddHours(5);

MF.GetFullMoonDates(dDate, ref dtMoonDates);



for(int iCount=0;iCount<10;iCount++)
{

TextBox tb = (TextBox)this.Controls["txtFullMoonDates" + iCount.ToString()];
tb.Text = dtMoonDates[iCount];

}


}

I am passing an empty array of strings (dtMoonDates) to MF.GetFullMoonDates that fills this array with formatted date 'strings'.

I have 10 textboxes named txtFullMoonDates1 to txtFullMoonDates9 so that I can loop and fill them.

The last line of this code "tb.Text = dtMoonDates[iCount]; is generating the error.

The exception details is "Object reference not set to an instance of an object."

I think it is referring to the Textbox "tb".

I'm baffled.