我试图将这3个标签加在一起。其中2个对应全局变量,3个对应2个全局变量的税收计算。当我使用该程序时,它只添加两个全局变量而不是最终的税号。
Sub bill()
Total = Val(lblRefreshmentPrice) + Val(lblTicketprice)
lblBillTaxPrice = Format(Total * 0.13, "Currency")
End Sub
Private Sub Form_Load()
lblRefreshmentPrice = RefreshmentPrice
lblTicketprice = Ticketprice
lblFinalTotalPrice = Val(lblRefreshmentPrice) + Val(lblTicketprice) + Val(lblBillTaxPrice)
Call bill
End Sub
答案 0 :(得分:1)
不确定哪些不适合你,我只是把它清理干净了。
Private RefreshmentPrice As Currency
Private TicketPrice As Currency
Private BillTaxPrice As Currency
Private FinalTotalPrice As Currency
Private Total As Currency
Const TaxRate As Double = 0.13
Sub bill()
' calculate total before tax
Total = RefreshmentPrice + TicketPrice
' calculate tax
BillTaxPrice = Total * TaxRate
' calculate total price with tax
FinalTotalPrice = RefreshmentPrice + TicketPrice + BillTaxPrice
' set labels
lblRefreshmentPrice.Caption = Format(RefreshmentPrice, "Currency")
lblTicketprice.Caption = Format(TicketPrice, "Currency")
lblFinalTotalPrice.Caption = Format(FinalTotalPrice, "Currency")
lblBillTaxPrice.Caption = Format(BillTaxPrice, "Currency")
End Sub
Private Sub Form_Load()
' set up globals (for debug)
RefreshmentPrice = 8
TicketPrice = 50
' calculate and set labels
bill
End Sub