Reputation: 39
I'm trying to add these 3 labels together. 2 of which correspond to global variables and the 3rd corresponds to a tax calculation of the 2 global variables. When I use the program it's only adding the two global variables and not the final tax label.
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
Upvotes: 1
Views: 404
Reputation: 15774
Not sure what's not working for you, I just cleaned it up.
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
Upvotes: 1