I need to make an application that can calculate the items the user chooses from

There is 7 different items the user can choose from

Small Coffee $4.95
Medium Coffee $6.87
Large Coffee $8.52
Bagel $2.99
Cream $0.71
Sugar $0.50
Lid $0.99


Total the coffee order (subtotal + tax at 6% = grand total)

Allow the user to delete items from the customer order and to allow the user to start the order for a new customer (clear all).

Create a button that gives a 10% discount for coffee only and adjusts the subtotal, tax, and total. Make certain the user can not click the button more than once per customer and if an item is removed from the customer order, make sure the discounted price is removed rather than the list price of the coffee. The button can only be clicked after the coffee is ordered, not before the coffee is selected.

This is what I got so far

Public Class Form1
    Private myCoolCheckBoxPrices() As Double = {4.95, 6.87, 8.52, 2.99, 0.71, 0.5, 0.99}
    Private myTax As Double = 0.06 'Tax used to add to Total Price
    Private Sub lstItems_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstItems.DoubleClick
        'customer double clicks on item and it is added to order list and adds to totals

    End Sub


    Private Sub lstOrder_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstOrder.SelectedIndexChanged
        'customer double clicks on item and it is removed from list and removed from totals

    End Sub

    Private Sub btnNewCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewCustomer.Click
        'clear the customer order and set the totals to zero

    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

You can create a comboBox that will show the user the product options, and for each item index assign a price using a select case decision.

When the client adds something, add the amount associated to the comboBox index to an accumulator variable (such as subtotal , and when he removes, substract the associated value from it.

As for the discount button, I guess it's pretty much self explanatory.

Come back when you've worked your way throughout the code, ok pal?

See if this helps.

Public Class Form1
    Private myItemPrices() As Double = {4.95, 6.87, 8.52, 2.99, 0.71, 0.5, 0.99} '// item Prices.
    Private myTax As Double = 0.06 '// Tax used to add to Total Price.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With ListBox1.Items
            .Add("Small Coffee") : .Add("Medium Coffee") : .Add("Large Coffee") : .Add("Bagel")
            .Add("Cream") : .Add("Sugar") : .Add("Lid")
        End With
        Button1.Text = "New Order"
    End Sub

    '// New Order.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox2.Items.Clear() '// clear Orders from ListBox.
        Label1.Text = CDec("0").ToString("c") '// reset Total Price Label.
    End Sub

    '// items the user can choose from.
    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        If Not ListBox1.SelectedIndex = -1 Then '// check if item is selected since -1 equals a no item selected index.
            ListBox2.Items.Add(ListBox1.SelectedItem) '// add Item to Order List.
            '// get Total Price.
            getTotalPrice(ListBox1, ListBox2, Label1)
        End If
    End Sub

    '// items on the order list. 
    Private Sub ListBox2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.DoubleClick
        If Not ListBox2.SelectedIndex = -1 Then '// check if item is selected since -1 equals a no item selected index.
            ListBox2.Items.Remove(ListBox2.SelectedItem) '// remove item from Order List.
            '// get Total Price.
            getTotalPrice(ListBox1, ListBox2, Label1)
        End If
    End Sub

    Private Sub getTotalPrice(ByVal itemsListListBox As ListBox, ByVal orderListListBox As ListBox, ByVal priceTotalLabel As Label)
        Dim myTotal As Double = 0
        For Each itm As String In orderListListBox.Items '// loop thru order items.
            '// check if itm is an item in your items ListBox. Items(0)=item 1, Items(1)=item 2, etc.
            If itm = itemsListListBox.Items(0).ToString Then myTotal += myItemPrices(0)
            If itm = itemsListListBox.Items(1).ToString Then myTotal += myItemPrices(1)
            If itm = itemsListListBox.Items(2).ToString Then myTotal += myItemPrices(2)
            If itm = itemsListListBox.Items(3).ToString Then myTotal += myItemPrices(3)
            If itm = itemsListListBox.Items(4).ToString Then myTotal += myItemPrices(4)
            If itm = itemsListListBox.Items(5).ToString Then myTotal += myItemPrices(5)
            If itm = itemsListListBox.Items(6).ToString Then myTotal += myItemPrices(6)
        Next
        priceTotalLabel.Text = (myTotal + (myTotal * myTax)).ToString("c") '// Total with Tax included.
    End Sub
End Class

As for the discount, use a Boolean.
Set it False on New Orders, when discount Button is clicked, check if Not True then set it to True and give the discount.

that kinda what im looking for, but when an item is selected and moved over to listbox2, there should be three different labels separating everything a subtotal,tax and total label, so the user can see how much is seperatly, itll might be a lil easier to explain if I should you a pic of the application to show you, how do I add a pic to a thread?

See if this helps.

Label1.Text = myTotal.ToString("c") '// Total.
        Label2.Text = (myTotal * myTax).ToString("c") '// Tax.
        Label3.Text = (myTotal + (myTotal * myTax)).ToString("c") '// Total with Tax included.

ok I put the code in and where its suppose to be, but it keeps coming up with an error on the myTotal, but the only ones that comes up that have the error are the three lines that I just put in, nothing else, is it because myTotal isnt declared or something

Private Sub lblSubtotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblSubtotal.Click
        lblSubtotal.Text = myTotal.ToString("c") '// Total.
    End Sub

    Private Sub lblTax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTax.Click
        lblTax.Text = (myTotal * myTax).ToString("c") '// Tax.
    End Sub

    Private Sub lblTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTotal.Click
        lblTotal.Text = (myTotal + (myTotal * myTax)).ToString("c") '// Total with Tax included.
    End Sub
End Class

Declare myTotal at Class Level.

Private myTotal As Double = 0

Then reset it in the Private Sub getTotalPrice to "0".

Private Sub getTotalPrice(ByVal itemsListListBox As ListBox, ByVal orderListListBox As ListBox, ByVal priceTotalLabel As Label)
        myTotal = 0
        For Each itm As String In orderListListBox.Items '// loop thru order items.

This is what I got all together but theres still a problem with the amount being put in the subtotal, tax, and total places. I have a picture attached so you can see where its suppose to be, but the amount keeps on going into the "Menu items" label instead of the 0.00 labels

Public Class Form1
    Private myItemPrices() As Double = {4.95, 6.87, 8.52, 2.99, 0.71, 0.5, 0.99} '// item Prices.
    Private myTax As Double = 0.06 '// Tax used to add to Total Price.
    Private myTotal As Double = 0

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With lstItems.Items
            .Add("Small Coffee") : .Add("Medium Coffee") : .Add("Large Coffee") : .Add("Bagel")
            .Add("Cream") : .Add("Sugar") : .Add("Lid")
        End With
        btnNewCustomer.Text = "New Order"
    End Sub

    '// New Order.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewCustomer.Click
        lstOrder.Items.Clear() '// clear Orders from ListBox.
        Label11.Text = CDec("0").ToString("c") '// reset Total Price Label.
    End Sub

    '// items the user can choose from.
    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstItems.DoubleClick
        If Not lstItems.SelectedIndex = -1 Then '// check if item is selected since -1 equals a no item selected index.
            lstOrder.Items.Add(lstItems.SelectedItem) '// add Item to Order List.
            '// get Total Price.
            getTotalPrice(lstItems, lstOrder, Label11)
        End If
    End Sub

    '// items on the order list. 
    Private Sub ListBox2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstOrder.DoubleClick
        If Not lstOrder.SelectedIndex = -1 Then '// check if item is selected since -1 equals a no item selected index.
            lstOrder.Items.Remove(lstOrder.SelectedItem) '// remove item from Order List.
            '// get Total Price.
            getTotalPrice(lstItems, lstOrder, Label11)
        End If
    End Sub

    Private Sub getTotalPrice(ByVal itemsListListBox As ListBox, ByVal orderListListBox As ListBox, ByVal priceTotalLabel As Label)
        myTotal = 0
        For Each itm As String In orderListListBox.Items '// loop thru order items.
            '// check if itm is an item in your items ListBox. Items(0)=item 1, Items(1)=item 2, etc.
            If itm = itemsListListBox.Items(0).ToString Then myTotal += myItemPrices(0)
            If itm = itemsListListBox.Items(1).ToString Then myTotal += myItemPrices(1)
            If itm = itemsListListBox.Items(2).ToString Then myTotal += myItemPrices(2)
            If itm = itemsListListBox.Items(3).ToString Then myTotal += myItemPrices(3)
            If itm = itemsListListBox.Items(4).ToString Then myTotal += myItemPrices(4)
            If itm = itemsListListBox.Items(5).ToString Then myTotal += myItemPrices(5)
            If itm = itemsListListBox.Items(6).ToString Then myTotal += myItemPrices(6)
        Next
        priceTotalLabel.Text = (myTotal + (myTotal * myTax)).ToString("c") '// Total with Tax included.
    End Sub


 
    Private Sub lblSubtotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblSubtotal.Click
        lblSubtotal.Text = myTotal.ToString("c") '// Total.
    End Sub

    Private Sub lblTax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTax.Click
        lblTax.Text = (myTotal * myTax).ToString("c") '// Tax.
    End Sub

    Private Sub lblTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTotal.Click
        lblTotal.Text = (myTotal + (myTotal * myTax)).ToString("c") '// Total with Tax included.
    End Sub
End Class
Attachments starduck_pic.png 43.2 KB

>>...but the amount keeps on going into the "Menu items" label instead of the 0.00 labels
Probably because "Label11" is your "Menu items" Label.:-O

'// get Total Price.
getTotalPrice(lstItems, lstOrder, Label11)

You can either add more Paramters to your Private Sub getTotalPrice for each Label needed, or remove the last Parameter for the Label.

Private Sub getTotalPrice(ByVal itemsListListBox As ListBox, ByVal orderListListBox As ListBox)
        myTotal = 0
        For Each itm As String In orderListListBox.Items '// loop thru order items.
            '// check if itm is an item in your items ListBox. Items(0)=item 1, Items(1)=item 2, etc.
            If itm = itemsListListBox.Items(0).ToString Then myTotal += myItemPrices(0)
            If itm = itemsListListBox.Items(1).ToString Then myTotal += myItemPrices(1)
            If itm = itemsListListBox.Items(2).ToString Then myTotal += myItemPrices(2)
            If itm = itemsListListBox.Items(3).ToString Then myTotal += myItemPrices(3)
            If itm = itemsListListBox.Items(4).ToString Then myTotal += myItemPrices(4)
            If itm = itemsListListBox.Items(5).ToString Then myTotal += myItemPrices(5)
            If itm = itemsListListBox.Items(6).ToString Then myTotal += myItemPrices(6)
        Next
        lblSubtotal.Text = myTotal.ToString("c") '// Total.
        lblTax.Text = (myTotal * myTax).ToString("c") '// Tax.
        lblTotal.Text = (myTotal + (myTotal * myTax)).ToString("c") '// Total with Tax included.
    End Sub

And use this to call the getTotalPrice Sub.

getTotalPrice(lstItems, lstOrder)

Btw, does StarDucks have good coffee?:D

Ok there it goes, but I kinda realize something, when I double click on what I want it moves over to the next column (what it should do), then subtotal, tax, and total comes up where its suppose to go (what it should do), but when I hit button new order, it clears the order, but the subtotal, tax and total, remains the same, until I double click a new item, is there a way to clear the items and reset the amount for suibtotal, tax, and total back to 0?

Also I need to create a button that gives a 10% discount for coffee only and adjusts the subtotal, tax, and total. The user cant click the button more than once per customer and if an item is removed from the customer order the discounted price is removed rather than the list price of the coffee. The button can only be clicked after the coffee is ordered, not before the coffee is selected.

Is your "Menu items" Label showing "$0.00"?
.Try adding the other Labels in the btnNewCustomer.Click event instead of Label11.

As for the discount, view the last part of my first post and reply back if you have any issues.
.The Boolean should also be declared at Class Level as you recently declared myTotal .

The label11 is actually for the “Menu items” label and that was just put there for the user to know whats in there, it has nothing to do with the actual application code
The new customer button is the Button1_Click

I Tried adding the other Labels to btnNewCustomer.Click but I don’t know if I did them wrong, these are what I put for them

lblSubtotal.Items.Clear()

lblSubtotal.Text.Items.Clear()

but it keeps coming up with the lblSubtotal as an error and I didn’t try the other ones, because this one isn’t working right, I don’t know if I should declare them to make them work or did I write the code wrong

But, I don’t know if my code is a lil different from yours but heres what I got

Public Class Form1
    Private myItemPrices() As Double = {4.95, 6.87, 8.52, 2.99, 0.71, 0.5, 0.99} '// item Prices.
    Private myTax As Double = 0.06 '// Tax used to add to Total Price.
    Private myTotal As Double = 0


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With lstItems.Items
            .Add("Small Coffee") : .Add("Medium Coffee") : .Add("Large Coffee") : .Add("Bagel")
            .Add("Cream") : .Add("Sugar") : .Add("Lid")
        End With
        btnNewCustomer.Text = "New Order"
    End Sub

    '// New Order.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewCustomer.Click ' button for the new customer
        lstOrder.Items.Clear() '// clear Orders from ListBox.


    End Sub

    '// items the user can choose from.
    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstItems.DoubleClick
        If Not lstItems.SelectedIndex = -1 Then '// check if item is selected since -1 equals a no item selected index.
            lstOrder.Items.Add(lstItems.SelectedItem) '// add Item to Order List.
            '// get Total Price.
            getTotalPrice(lstItems, lstOrder)
        End If
    End Sub

    '// items on the order list. 
    Private Sub ListBox2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstOrder.DoubleClick
        If Not lstOrder.SelectedIndex = -1 Then '// check if item is selected since -1 equals a no item selected index.
            lstOrder.Items.Remove(lstOrder.SelectedItem) '// remove item from Order List.
            '// get Total Price.
            getTotalPrice(lstItems, lstOrder)
        End If
    End Sub

    Private Sub getTotalPrice(ByVal itemsListListBox As ListBox, ByVal orderListListBox As ListBox)
        myTotal = 0
        For Each itm As String In orderListListBox.Items '// loop thru order items.
            '// check if itm is an item in your items ListBox. Items(0)=item 1, Items(1)=item 2, etc.
            If itm = itemsListListBox.Items(0).ToString Then myTotal += myItemPrices(0)
            If itm = itemsListListBox.Items(1).ToString Then myTotal += myItemPrices(1)
            If itm = itemsListListBox.Items(2).ToString Then myTotal += myItemPrices(2)
            If itm = itemsListListBox.Items(3).ToString Then myTotal += myItemPrices(3)
            If itm = itemsListListBox.Items(4).ToString Then myTotal += myItemPrices(4)
            If itm = itemsListListBox.Items(5).ToString Then myTotal += myItemPrices(5)
            If itm = itemsListListBox.Items(6).ToString Then myTotal += myItemPrices(6)
        Next
        lblSubtotal.Text = myTotal.ToString("c") '// Total.
        lblTax.Text = (myTotal * myTax).ToString("c") '// Tax.
        lblTotal.Text = (myTotal + (myTotal * myTax)).ToString("c") '// Total with Tax included.
    End Sub



    Private Sub lblSubtotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblSubtotal.Click
        lblSubtotal.Text = myTotal.ToString("c") '// Total.
    End Sub

    Private Sub lblTax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTax.Click
        lblTax.Text = (myTotal * myTax).ToString("c") '// Tax.
    End Sub

    Private Sub lblTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTotal.Click
        lblTotal.Text = (myTotal + (myTotal * myTax)).ToString("c") '// Total with Tax included.
    End Sub
End Class

See if this helps.

'// New Order.
    Private Sub btnNewCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewCustomer.Click ' button for the new customer
        lstOrder.Items.Clear() '// clear Orders from ListBox.
        lblSubtotal.Text = CDec("0").ToString("c") '// reset SubTotal Price Label.
        '// use that .Text value to add to the other TextBoxes.
        lblTax.Text = lblSubtotal.Text '// Tax.
        lblTotal.Text = lblSubtotal.Text '// Total with Tax included.
    End Sub

For future references, unless the entire code changed, only post the part of the code have issues with. Thanks.

Thats perfect and everything is working the way its suppose to be, thanks

This question has already been answered. Start a new discussion instead.