Hi Good Guys,
I need your help. Please help me. Thank you.
I am learning how to create and use DELEGATE Class and apprently my coding at the FRMMAIN.cs which is using the DELEGATE CLASS Method propCalculate.
This is the error message generate from the FRMMAIN :
Error 1 The name 'propcalculate' does not exist in the current context
CODING FROM FrmMAIN.CS
private void btnCalculate_Click(object sender, EventArgs e) { if ((this.txtLoanAmt.TextLength != 0) && (this.txtIntRate.TextLength !=0)) { txtAmt = Convert.ToDouble(this.txtLoanAmt.Text); txtInt = Convert.ToDouble(this.txtIntRate.Text); clsDelegate = new ClassDelegateCalculate.DelegateCalculate(txtAmt, txtInt) ; this.intTotalLoan = clsDelegate.propCalculate; <-----Error from here ****** intPayMth = (intTotalLoad /= 12); this.lblTotalLoan.Text = Convert.ToString(intTotalLoan); this.lblPayMth.Text = Convert.ToString(intPayMth); } }
|
HERE ARE THE DELEGATE CLASS CODING WHICH MAY NOT BE PERFECT OR CORRECT
namespace CSharpDelegate { class ClassDelegateCalculate { //declare the DelegateCalculatonClass public delegate double DelegateCalculate(double LoanAmt, double interest); private double dblLoanAmt; private double dblInterest; //------ constructor normal -------------- public ClassDelegateCalculate() { this.dblLoanAmt = 0; this.dblInterest = 0; }
//----- constructor override ------------------------------------ public ClassDelegateCalculate(double Loan, double YearInt) { this.dblLoanAmt = Loan; this.dblInterest = YearInt; } //--------class methods ------------------------------------- public Double propCalculate() //return variable back to calling Program FrmMain { //calculate interest on loan amount double dblTotalAmt; this.dblTotalAmt = ( (this.dblLoanAmt * this.dblInterest) /= 100); return (dblTotalAmt); } } }
|
Please help me. I am totally new to DELEGATE CLASS.
Thank You.
Have a Good Day,
Cheers,
Lennie
Lennie KuahPosted Sep 20, 2010, 12:35 AM
I did modify the coding with Parenthese and it still generate error message from the FrmMain coding and also from ClassDelegate coding
Here are the message and coding from FrmMain.cs
Error 1 Method name expected 54 78 CSharpDelegate
Error 2 'CSharpDelegate.ClassDelegateCalculate.DelegateCalculate' does not contain a definition for 'propCalculate' and no extension method 'propCalculate' accepting a first argument of type 'CSharpDelegate.ClassDelegateCalculate.DelegateCalculate' could be found (are you missing a using directive or an assembly reference?)
private void btnCalculate_Click(object sender, EventArgs e)
{
if ((this.txtLoanAmt.TextLength != 0) && (this.txtIntRate.TextLength !=0))
{
txtAmt = Convert.ToDouble(this.txtLoanAmt.Text);
txtInt = Convert.ToDouble(this.txtIntRate.Text);
clsDelegate = new ClassDelegateCalculate.DelegateCalculate(txtAmt, txtInt);
this.intTotalLoan = clsDelegate.propCalculate(); <--- error message from here
intPayMth = (intTotalLoan /= 12);
this.lblTotalLoan.Text = Convert.ToString(intTotalLoan);
this.lblPayMth.Text = Convert.ToString(intPayMth);
}
}
-----------------------------------------------------------------
Error message from ClassDelegate coding
Error 3 The left-hand side of an assignment must be a variable, property or indexer
//class methods
public Double propCalculate()
//return variable back to calling Program
{
//calculate interest on loan amount
dblTotalAmt = (( dblLoanAmt * dblInterest) /= 100); <--- Error message from here
return (dblTotalAmt);
}
Sam HobbsPosted Sep 20, 2010, 12:03 AM
Try that and if it does not solve the problemn, let us know.
I hope the big Kiwi quake about 6 weeks ago had no affect or little affect on you and your friends and family.