Option Explicit
Dim ricePrices As Object
Dim totalAmount As Double
Private Sub UserForm_Initialize()
Set ricePrices = CreateObject("[Link]")
' Suggested Retail Price (SRP) per kilo
[Link] "Sinandomeng", 45
[Link] "Dinorado", 50
[Link] "Jasmine", 55
[Link] "Malagkit", 60
Dim key As Variant
For Each key In [Link]
[Link] key
Next key
totalAmount = 0
[Link] = "Total: ₱0.00"
End Sub
Private Sub cmdAdd_Click()
Dim riceType As String
Dim kilos As Double
Dim pricePerKilo As Double
Dim discount As Double
Dim finalPrice As Double
Dim lineTotal As Double
If [Link] = -1 Then
MsgBox "Please select a rice type.", vbExclamation
Exit Sub
End If
If Not IsNumeric([Link]) Or Val([Link]) <= 0 Then
MsgBox "Enter a valid number of kilos.", vbExclamation
Exit Sub
End If
riceType = [Link]
kilos = Val([Link])
pricePerKilo = ricePrices(riceType)
' Apply wholesale discount: 5% off if kilos >= 25
If kilos >= 25 Then
discount = 0.05
Else
discount = 0
End If
finalPrice = pricePerKilo * (1 - discount)
lineTotal = kilos * finalPrice
[Link] riceType & " - " & kilos & "kg @ ₱" & Format(finalPrice, "0.00") & " = ₱" &
Format(lineTotal, "0.00")
totalAmount = totalAmount + lineTotal
[Link] = "Total: ₱" & Format(totalAmount, "0.00")
' Clear inputs
[Link] = -1
[Link] = ""
End Sub
Private Sub cmdCheckout_Click()
If [Link] = 0 Then
MsgBox "Cart is empty!", vbInformation
Exit Sub
End If
MsgBox "Total Amount Due: ₱" & Format(totalAmount, "0.00"), vbInformation, "Checkout"
' Reset
[Link]
totalAmount = 0
[Link] = "Total: ₱0.00"
End Sub