Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 132,246 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,129 people online right now. Registration is fast and FREE... Join Now!




Shopping Cart app in Visual Basic using arrays

 
Reply to this topicStart new topic

Shopping Cart app in Visual Basic using arrays

blgtn2000
post 3 Mar, 2008 - 05:31 AM
Post #1


New D.I.C Head

*
Joined: 20 Feb, 2008
Posts: 4

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 => code.gif

This post has been edited by PsychoCoder: 3 Mar, 2008 - 06:16 AM
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 3 Mar, 2008 - 06:20 AM
Post #2


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,923



Thanked 117 times

Dream Kudos: 8475

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Thats because as your code sits it doesnt add to the total, the way it is written just overwrites the original value, try changing to this:


vb

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
User is online!Profile CardPM

Go to the top of the page

333bob333
post 5 Apr, 2008 - 01:28 AM
Post #3


New D.I.C Head

*
Joined: 5 Apr, 2008
Posts: 1

How did you create the cart?

Hi, i've been trying to create a shopping cart (visual web dev 2008) , and found a two ways to do this.

Or a database driven cart (no, i won't do this) or a session variables cart.

In the session variable cart, to each product I add session.add("productname"," qty") and it should work after displaying the cart byy link with the database.
So for each item selected by the customer, I have a product name stored and an quantity stored.
Linking this after with the database, I will find the price and everything.

But I only store two variables, product name and qty.

And what if there was a third variable, like the size (or the color of the product).

How can I also store this third variable ?

Got an Idea ?
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 5 Apr, 2008 - 04:24 AM
Post #4


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,923



Thanked 117 times

Dream Kudos: 8475

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Moved to VB.NET
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 10:25PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month