Reputation: 1121
I am totally stuck on this assignment for class. I have a program that calculates sales taxes and percents.. but I need to have 3 accumulating text boxes; i.e When the user enters their subtotal, itll save to a variable and then the next time they enter somthing, it'll add it to that same variable and display it. I have been at this for hours and have no luck and keep getting errors.
Dim numberOfInvoices As Integer
Dim totalOfInvoices As Decimal
Dim invoiceAverage As Decimal
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim subtotal As Decimal = CDec(txtEnterSubtotal.Text)
Dim discountPercent As Decimal = 0.25D
Dim discountAmount As Decimal = Math.Round(subtotal * discountPercent, 2)
Dim invoiceTotal As Decimal = subtotal - discountAmount
Dim accumSubtotal As Decimal = subtotal
txtSubtotal.Text = FormatCurrency(subtotal)
txtDiscountPercent.Text = FormatPercent(discountPercent, 1)
txtDiscountAmount.Text = FormatCurrency(discountAmount)
txtTotal.Text = FormatCurrency(invoiceTotal)
numberOfInvoices += 1
totalOfInvoices += invoiceTotal
invoiceAverage = totalOfInvoices / numberOfInvoices
Me.txtNumberOfInvoices.Text = numberOfInvoices.ToString
Me.txtTotalOfInvoices.Text = FormatCurrency(totalOfInvoices)
Me.txtInvoiceAverage.Text = FormatCurrency(invoiceAverage)
'-------This is where i've been trying to accumulate values------'
'I need to accumulate the subtotal everytime the user enters something
'txtAccumSubtotal.text = 'the variable that adds evertime a new number is input into txtEnterSubtotal.text
txtEnterSubtotal.Text = ""
txtEnterSubtotal.Select()
'This is a comment
End Sub
Hopefully I explained this right in the code. I really need help with this.
Upvotes: 1
Views: 1148
Reputation: 38865
Every time they click, you are assigning the current SubTotal to AccumSubTotal. Declare Accum Sub outside the Click event, then add the new SubTotal to it.
Give it a try...I'd show code, but you do wanna learn, no? Hint:
AccumSubTotal += subtotal
or old school
AccumSubTotal = AccumSubTotal + subtotal
Upvotes: 1