无法实现新赋予的值到 subtotaldecimal里面
Public Class Form1
Const Primerib_Rate_Price As Decimal = 25.95
Const Chicken_Rate_Price As Decimal = 18.95
Const Pasta_Rate_Price As Decimal = 12.95
Const Openbar_Rate_Price As Decimal = 25.0
Const Winewithdinner_Rate_price As Decimal = 8.0
Const Tax_Rate As Decimal = 0.09
Private Sub ButtonCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCalculate.Click
Dim numberoforderAmount As Integer
Dim pricedecimal, foodpricedecimal, totalpricedecimal, subtotaldecimal ,itemamountdecimal As Decimal
Dim drinkpricedecimal As Decimal = 0.0
Dim taxdecimal As Decimal = 0.0
If RadioButtonPrimeRib.Checked = True Then
pricedecimal = Pasta_Rate_Price
ElseIf RadioButtonChicken.Checked = True Then
pricedecimal = Chicken_Rate_Price
ElseIf RadioButtonPasta.Checked = True Then
pricedecimal = Pasta_Rate_Price
End If
If CheckBoxOpenBar.Checked = True And CheckBoxWinewithDinner.Checked = False Then
drinkpricedecimal = Openbar_Rate_Price
End If
If CheckBoxOpenBar.Checked = False And CheckBoxWinewithDinner.Checked = True Then
drinkpricedecimal = Winewithdinner_Rate_price
End If
If CheckBoxOpenBar.Checked = True And CheckBoxWinewithDinner.Checked = True Then
drinkpricedecimal = Openbar_Rate_Price + Winewithdinner_Rate_price
End If
Try
numberoforderAmount = Integer.Parse(TextbookNumberofOrder.Text)
itemamountdecimal = pricedecimal * numberoforderAmount + drinkpricedecimal
subtotaldecimal += itemamountdecimal
taxdecimal = itemamountdecimal * Tax_Rate
totalpricedecimal = subtotaldecimal * 1.09
LabelItemamount.Text = itemamountdecimal.ToString("N")
LabelSubtotal.Text = subtotaldecimal.ToString("N")
LabelTax.Text = Tax_Rate.ToString("C")
LabelTotalDue.Text = totalpricedecimal.ToString("N")
Catch ex As Exception
End Try
End Sub
End Class
程序是让结算价格,之后可以多次添加结算的消费价格。
但是无法将之前的数据存储下来,不知道哪一个数据写错了,希望大家帮忙
[解决办法]
Dim pricedecimal, foodpricedecimal, totalpricedecimal, subtotaldecimal ,itemamountdecimal As Decimal
把上面的变量设成类成员变量(即全局变量,放在窗体类里定义,不要放在click事件里定义)
[解决办法]
If RadioButtonPrimeRib.Checked = True Then
pricedecimal = Pasta_Rate_Price
ElseIf RadioButtonChicken.Checked = True Then
pricedecimal = Chicken_Rate_Price
ElseIf RadioButtonPasta.Checked = True Then
pricedecimal = Pasta_Rate_Price
End If
If RadioButtonPrimeRib.Checked = True Then
pricedecimal = Pasta_Rate_Price
ElseIf RadioButtonChicken.Checked = True Then
pricedecimal = Chicken_Rate_Price
ElseIf RadioButtonPasta.Checked = True Then
pricedecimal = Pasta_Rate_Price
End If