Hello,
I am trying to create a shopping cart in Visual Basic. I have most of it figured out. However, when I click the Add Cart button, the item will add; however, when I add a new item, it will not go to the next line to display it. It instead replaces the first item I added. For example if the user chooses 1111 for the part number and qty is 2 then clicks the Add to Cart button, the following will show in a group box below:
1111 Alarm Clock 2 $19.95 $39.90
If the person wants to add part number 2222 and qty is 2, that relating info should show up below the first entry of the Alarm clock. In my code, it's not doing that, it's just replacing the first line (alarm clock entry). However, it is keeping track of the total amount added to the cart.
Here is my code that I have done for the Add Cart button:
vb
Private Sub xAddButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xAddButton.Click
Dim searchFor As String
Dim subscript As Integer
Dim qty As Integer
Dim totalprice As Double
Integer.TryParse(Me.xQtyTextBox.Text, qty)
'assign the part number to a variable
searchFor = Me.xPartComboBox.SelectedItem
'search the parts number array for the part number
Do Until subscript = partNumber.Length _
OrElse searchFor = partNumber(subscript)
subscript = subscript + 1
Loop
Me.xPartlabel.Text = Me.xPartComboBox.SelectedItem.ToString & ControlChars.NewLine
Me.xDescLabel.Text = desc(subscript).ToString & ControlChars.NewLine
Me.xQty.Text = Me.xQtyTextBox.Text.ToString & ControlChars.NewLine
Me.xUnitPriceLabel.Text = unitPrice(subscript).ToString("C2") & ControlChars.NewLine
totalprice = qty * unitPrice(subscript)
Me.xTotalPriceLabel.Text = totalprice.ToString("C2") & ControlChars.NewLine
newtotalprice = newtotalprice + totalprice
Me.xQtyTextBox.Text = String.Empty
Me.xPartComboBox.SelectedIndex = 0
Me.xPartComboBox.Text = Focus()
End Sub
Here are the arrays I created:
vb
Private partNumber() As String = {"1111", "2222", "3333", "4444", "5555", "6666"}
Private desc() As String = {"Alarm Clock", "USB Flash Drive", "Wireless Mouse", "10-Pack CD-R", _
"Stereo Headphones", "MP3 Player"}
Private unitPrice() As Decimal = {19.95D, 22.95D, 9.95D, 3.99D, 35.5D, 50D}
Please use code tags when posting your code =>
This post has been edited by PsychoCoder: 3 Mar, 2008 - 06:16 AM