Hi. I'm nearly as new to C# as I am to this forum. Anyway, errors regarding names not existing in the current context arise when the following code is used:
For all the lines marked with a red line comment, the error arises. I'd like to know why txtDiscountAmount.Text is recognized, but let's say txtNumberOfInvoices.Text isn't.Code:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace InvoiceTotal { public partial class frmInvoiceTotal : Form { public frmInvoiceTotal() { InitializeComponent(); } int numberOfInvoices = 0; decimal totalOfInvoices = 0m; decimal invoiceAverage = 0m; private void btnCalculate_Click(object sender, EventArgs e) { decimal subtotal = Convert.ToDecimal(txtSubtotal.Text); decimal discountPercent = .25m; decimal discountAmount = Math.Round(subtotal * discountPercent, 2); decimal invoiceTotal = subtotal - discountAmount; txtSubtotal.Text = subtotal.ToString("c"); txtDiscountPercent.Text = discountPercent.ToString("p1"); txtDiscountAmount.Text = discountAmount.ToString("c"); txtTotal.Text = invoiceTotal.ToString("c"); numberOfInvoices++; totalOfInvoices += invoiceTotal; invoiceAverage = totalOfInvoices / numberOfInvoices; txtNumberOfInvoices.Text = numberOfInvoices.ToString(); //red line txtTotalOfInvoices.Text = totalOfInvoices.ToString("c"); //red line txtDiscountAmount.Text = invoiceAverage.ToString("c"); //no red underline for this line txtEnterSubtotal.Text = invoiceAverage.ToString("c"); //red line txtSubtotal.Focus(); } private void btnClearTotals_Click(object sender, System.EventArgs e) { numberOfInvoices = 0; totalOfInvoices = 0m; invoiceAverage = 0m; txtNumberOfInvoices.Text = ""; //red line txtTotalOfInvoices.Text = ""; //red line txtInvoiceAverage.Text = ""; //red line txtEnterSubtotal.Focus(); //red line } private void btnExit_Click(object sender, EventArgs e) { this.Close(); } } }
Thanks for reading.



LinkBack URL
About LinkBacks


