I need help with some homework... hopefully this is the right forum.
So my last project assignment is making a shopping cart and having the user add, remove items therefrom. I am having a problem adjusting the totals after the items get removed from the cart: Using Lists to show items in cart.
Structure Item Public strItemName As String Public dblPrice As Double End Structure Public Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load itmItem(0).strItemName = "The War" itmItem(0).dblPrice = 10 itmItem(1).strItemName = "Radio One" itmItem(1).dblPrice = 15 While intNum <= 2 lstItems.Items.Add(itmItem(intNum).strItemName) intNum += 1 End While End Sub Private Sub lstItems_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstItems.SelectedIndexChanged intSelected = lstItems.SelectedIndex lblPrice.Text = itmItem(intSelected).dblPrice.ToString("C2") End Sub Public Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click Dim intToCart As Integer = lstItems.SelectedIndex lstCart.Items.Add(lstItems.Items(intToCart)) dblSubtotal += itmItem(intToCart).dblPrice dblTax = dblSubtotal * dblTAR_RATE dblTotal = dblSubtotal + dblTax lblSubtotal.Text = dblSubtotal.ToString("C2") lblTax.Text = dblTax.ToString("C2") lblTotal.Text = dblTotal.ToString("C2") End Sub Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click Dim intIndex As Integer = lstCart.SelectedIndex lstCart.Items.RemoveAt(intIndex) End Sub
I ma havng a hard time defining the "names" that are already in "lstCart" as items (with a name and price property, this way I can just subtract the price property if the "removed item" from the total), the name being the same as the one in the lstCart list.
Any ideas would be welcome.