I am getting an error when I try to call a function from Form1.cs.
The function works properly when called from a button on the form. Instead of posting the code here you can see it in the following MSDN article.
http://msdn.microsoft.com/library/de...VisualCNET.asp
I adapted the code to create a control array of text boxes. In the section "creating a common event handler" the article demonstrates firing a message box that displays which control was clicked. What I want to do is call a function on the form which sums up all of the numbers in the text box whenever the number in a textbox is changed. So I am using
aHoursTextBox.TextChanged += new System.EventHandler(TextChangedHandler); in the AddNew method of the array class and I have the event handler setup so that I can trigger the same message box when the text is changed so I know that everything is correct except that I get the following error when I try to compile:
An object reference is required for the nonstatic field, method or property 'BCTimeEntry.TimeEntry.SumUp()'
Here is my SumUp method:
<div align="left">
public void SumUp()
{
int iRowCount = MyEarnCodeArray.Count;
double dReg = 0,dVac = 0,dPers = 0,dSick = 0,dJury =0,dBereav = 0;
string sEarnCode;
for (int i = 0; i < iRowCount ; i++)
{
//MessageBox.Show(Convert.ToString(iRowCount));
sEarnCode = MyEarnCodeArray[i].Text;
//MessageBox.Show(sEarnCode + " " + MyTotalHoursArray[i].Text);
switch(sEarnCode)
{
case "Reg":
dReg += Convert.ToDouble(MyTotalHoursArray[i].Text);
lblReg.Text = "Reg " + Convert.ToString(dReg);
break;
case "Vac":
dVac += Convert.ToDouble(MyTotalHoursArray[i].Text);
lblVac.Text = "Vac " + Convert.ToString(dVac);
break;
case "Pers":
dPers += Convert.ToDouble(MyTotalHoursArray[i].Text);
lblPers.Text = "Pers " + Convert.ToString(dPers);
break;
case "Sick":
dSick += Convert.ToDouble(MyTotalHoursArray[i].Text);
lblSick.Text = "Sick " + Convert.ToString(dSick);
break;
case "Jury":
dJury += Convert.ToDouble(MyTotalHoursArray[i].Text);
lblJury.Text = "Jury " + Convert.ToString(dJury);
break;
case "Bereav":
dBereav += Convert.ToDouble(MyTotalHoursArray[i].Text);
lblBereav.Text = "Bereav " + Convert.ToString(dBereav);
break;
}
}
}
</div id="left">
Can someone help me with the correct syntax for calling this method?
Thanks
Dan