how calculate items in different discount
plz help

## All 6 Replies

example is
hotdog quantity > 20 then discount is 10%
ham quantity > 10 then discount is 5%
cheese quantity > 30 then discount 15%

plz help :)

You need to show your code. We can't help you if we don't know where you are holding the food type or the quantity or where you want the results. Also you need to show that you've tried.

Show your form and explain a bit better what you are trying to accomplish (ie. is the discount for the particular line or for the whole order?)

``````If ListView1.SelectedItems.Count = 0 Then
MsgBox("Plese Select a Product")
Else
Dim price As Double
Dim quantity As Integer
Dim total As Double

price = ListView1.FocusedItem.SubItems(3).Text
quantity = ListView1.FocusedItem.SubItems(2).Text

If txtProductName.Text = "Happy" Then
If txtQuantity2.Text > 20 Then
total = price * Val(txtQuantity2.Text) * 0.95
total = Format(total, "0.00")
execute("insert into tblOrder Values('" & txtProductName.Text & "', '" & txtQuantity2.Text & "', '" & total & "')")
FillListview(execute("select * from tblOrder"), ListView2)
MsgBox("success")
ElseIf txtQuantity2.Text < 20 Then
total = price * Val(txtQuantity2.Text)
total = Format(total, "0.00")
execute("insert into tblOrder Values('" & txtProductName.Text & "', '" & txtQuantity2.Text & "', '" & total & "')")
FillListview(execute("select * from tblOrder"), ListView2)
MsgBox("success")
If txtProductName.Text = "Moby" Then
If txtQuantity2.Text > 15 Then
total = price * Val(txtQuantity2.Text) * 0.97
total = Format(total, "0.00")
execute("insert into tblOrder Values('" & txtProductName.Text & "', '" & txtQuantity2.Text & "', '" & total & "')")
FillListview(execute("select * from tblOrder"), ListView2)
MsgBox("success")
ElseIf txtQuantity.Text < 15 Then
total = price * Val(txtQuantity2.Text)
total = Format(total, "0.00")
execute("insert into tblOrder Values('" & txtProductName.Text & "', '" & txtQuantity2.Text & "', '" & total & "')")
FillListview(execute("select * from tblOrder"), ListView2)
MsgBox("success")
If txtProductName.Text = "Honey" Then
If txtQuantity2.Text > 25 Then
total = price * Val(txtQuantity2.Text) * 0.97
total = Format(total, "0.00")
execute("insert into tblOrder Values('" & txtProductName.Text & "', '" & txtQuantity2.Text & "', '" & total & "')")
FillListview(execute("select * from tblOrder"), ListView2)
MsgBox("success")
ElseIf txtQuantity.Text < 25 Then
total = price * Val(txtQuantity2.Text)
total = Format(total, "0.00")
execute("insert into tblOrder Values('" & txtProductName.Text & "', '" & txtQuantity2.Text & "', '" & total & "')")
FillListview(execute("select * from tblOrder"), ListView2)
MsgBox("success")``````

here sir the moby and honey is not working

Of course they won't work.
What you are doing wrong is nesting all the If's. So you are practically running this:

``````If txtProductName.Text = "Happy" Then
If txtProductName.Text = "Moby" Then
If txtProductName.Text = "Honey" Then``````

This translates to if txtproductname is Happy and txtproductname is Moby (which can never be true because you have already checked that txtproductname is Happy in order to get to the second if).
What you need to do in order to fix this is either add

``````End If
End If``````

(two End If - one for the quantity check and one for the product) before If txtProductName.Text = "Moby" Then and before If txtProductName.Text = "Honey" Then

``````End If
ElseIf``````

in the same places (replacing the If each time).

If the quantity for discount varies from item to item then I suggest you add it as well as the discount to your listview as a subitem. That way you wouldn't have to hardcode a test for each type of item. Also, your insert query is independent of the item type and discount so you can remove all the inserts from inside the selects and just do one insert after you have determined the discount.

``````'get item price and minimum limit needed for discount

price = CDbl(ListView1.FocusedItem.SubItems(3).Text)
limit = CInt(ListView1.FocusedItem.SubItems(?).Text)
quantity = CInt(ListView1.FocusedItem.SubItems(2).Text)
discount = CDbl(ListView1.FocusedItem.SubItems(?).Text

'determine price with possible discount

If quantity > limit Then
total = FormatCurrency(quantity * price * discount,2)
Else
total = FormatCurrency(quantity * price,2)
End If

'update database

execute("insert...")
FillListview(execute("select * from tblOrder"), ListView2)``````

Since Reverend Jim opened the issue of design, may I ask if this is a school assignment, an effort to learn or a true application you are building?