我完全被这个课堂作业困住了。我有一个计算销售税和百分比的程序。但我需要有 3 个累积文本框;即当用户输入他们的小计时,它会保存到一个变量中,然后下次他们输入时,它会将它添加到同一个变量中并显示它。我已经在这几个小时了,没有运气,并且不断出错。
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
希望我在代码中正确解释了这一点。我真的需要帮助。