0

所以我有这个程序。它计算商品的售价并显示税金、小计、折扣百分比,一切正常。我想做的是再显示 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 enterSubtotal As Decimal = Val(txtEnterSubtotal.Text)
    Dim accumDiscount As Decimal = Val(txtAccumDiscAmount.Text)
    Dim avgDiscount As Decimal = Val(txtAccumDiscAmount.Text)
    Dim accumSubTotal As Decimal = Val(txtAccumSubtotal.Text)

    txtSubtotal.Text = FormatCurrency(subtotal)
    txtDiscountPercent.Text = FormatPercent(discountPercent, 1)
    txtDiscountAmount.Text = FormatCurrency(discountAmount)
    txtTotal.Text = FormatCurrency(invoiceTotal)

    numberOfInvoices += 1
    totalOfInvoices += invoiceTotal
    invoiceAverage = totalOfInvoices / numberOfInvoices

    txtNumberOfInvoices.Text = numberOfInvoices.ToString
    txtTotalOfInvoices.Text = FormatCurrency(totalOfInvoices)
    txtInvoiceAverage.Text = FormatCurrency(invoiceAverage)

    'below is where I'm trying to accumulate everything entered....
    txtAccumSubtotal.Text = FormatCurrency(accumSubTotal + subtotal)
    txtAccumDiscAmount.Text = FormatCurrency(accumDiscount + discountAmount)

    If avgDiscount = 0 Then
        txtAvgDiscAmount.Text = FormatCurrency(discountAmount)
    ElseIf avgDiscount > 0 Then
        txtAvgDiscAmount.Text = FormatCurrency(avgDiscount / numberOfInvoices)
    End If

    txtEnterSubtotal.Text = ""
    txtEnterSubtotal.Select()
    'This is a comment
End Sub
4

1 回答 1

0

请忽略我之前的帖子,我错了。我发现了问题。

VAL()在百分比或货币字段上将返回 0。您必须从字符串中取出“$”和“%”才能执行VAL().

于 2013-09-25T22:45:45.357 回答