Hello! I'm new to VB and I'm having trouble finding the correct formula for the Average Discount :'(

Option Explicit
Dim mcurExtendedPrice As Currency
Dim mcurFifteenDiscount As Currency
Dim mcurDiscountedPrice As Currency
Dim mcurTotalDiscountGiven As Currency
Dim mcurBookCount As Currency
'Declare module-level variables
Private Sub cmdCompute_Click()
Dim intQuantity As Integer
Dim curPrice As Currency
Dim curAverageDiscount As Currency
Const curFifteenDiscount As Currency = 0.15
'Declare the local variables
intQuantity = Val(txtQuantity.Text)
curPrice = Val(txtPrice.Text)
'Convert text to numbers
mcurExtendedPrice = curPrice * intQuantity
mcurFifteenDiscount = mcurExtendedPrice * curFifteenDiscount
mcurDiscountedPrice = mcurExtendedPrice - mcurFifteenDiscount
mcurBookCount = mcurBookCount + intQuantity
mcurTotalDiscountGiven = mcurTotalDiscountGiven + mcurFifteenDiscount
curAD = ????Help???
lblEP.Caption = mcurExtendedPrice
lblF.Caption = mcurFifteenDiscount
lblDP.Caption = mcurDiscountedPrice
lblBC.Caption = mcurBookCount
lblTD.Caption = mcurTotalDiscountGiven
lblAD.Caption = curAverageDiscount
lblEP.Caption = FormatNumber(mcurExtendedPrice, 2)
lblF.Caption = FormatNumber(mcurFifteenDiscount, 2)
lblDP.Caption = FormatNumber(mcurDiscountedPrice, 2)
lblTD.Caption = FormatNumber(mcurTotalDiscountGiven, 2)
lblAD.Caption = FormatNumber(curAverageDiscount, 2)
txtP.Text = FormatCurrency(curPrice, 2)

End Sub

Private Sub cmdEnd_Click()
End Sub

Private Sub Command2_Click()
lblEP.Caption = ""
lblF.Caption = ""
lblDP.Caption = ""
txtP.Text = ""
txtQ.Text = ""
End Sub

If I put $10 as quantity and $500 as the price for the first transaction, the average discount should be $750.00. If I put $20 as quantity and $1000 as the price for the second transaction, the average discount should be $1875. If I put $25 in the quantity and $250 for price, the average discount should be $1562. Pls. help ASAP :'(. Still learning.

What formula are you using? What you have provided is not an explanation of what you are doing. All you did was post some poorly formatted code with comments that are either meaningless/unhelpful or just plain incorrect.


Quantity is number of the items so no need for $ sign.

Your formula on the first transaction is (10 * 500) * 0.15

then on the second transaction is (20 * 1000) * 0.09 but the result is 1800 no idea how to get 1875

then on the third transaction (25 * 250 ) * .25

this is your formula needed. You give 15% in first transaction and 9% for second and 25% in third.

Maybe post a picture atleast your design so they can help you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.