-
subtract one at a time??
i' ve got this code that i would like u to have a look at.
all i am trying to do is,decrease one quantity at a time, which leads to deacrasing the cost (this works fine) and decreasing totals. the totalQuantity works fine, but the Totalcost works for the 1st and 2nd "decreasing" times, then it messes up.
here it is:
Private Sub cmdMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMinus.Click
If lstProduct.SelectedIndex <> -1 Then 'Not lstQuantity.SelectedItem Nothing Then
quantity = CDbl(lstQuantity.Items(lstProduct.SelectedIndex))
'cost = CDec(lstCost.Items(lstProduct.SelectedIndex))
If quantity > 1 Then
quantity = quantity - 1
lstQuantity.Items.Remove(lstQuantity.Items(lstProduct.SelectedIndex))
lstQuantity.Items.Add(quantity)
totalQuantity = Val(lblTotalQuantity.Text) - 1
lblTotalQuantity.Text = CStr(totalQuantity)
totalQuantity = 0 ' Intialising totalQuantity
Dim changedCost As Decimal = CDec(lstCost.Items(lstProduct.SelectedIndex))
Dim changedTotal As Decimal = changedCost
changedCost = CDec((changedCost / (quantity + 1)) * quantity)
lstCost.Items.Remove(lstCost.Items(lstProduct.SelectedIndex))
lstCost.Items.Add(changedCost)
totalCost = totalCost - (changedTotal - changedCost)
lblTotalCost.Text = CStr(totalCost)
totalCost = 0
Else
MsgBox(" can't decrease quantity less than 1")
End If
Else
MsgBox(" Please select an Item")
End If
End Sub
it's slighlty messy ..so take your time, oh and if u have any tips to tide it up would be appreciated
thank u