How are you,

I created a simple cash register code that makes the user selects the order from different buttons. I have some problem figuring out the following:

1. How can I get the total (if the user selects 1 or 2 or 3 different orders). I need to find out the total no matter what the user selects and presses (ButtonDone) with the tax added. I could not figure out how to add the arrays based on the user selection.

2. I need to clear the (TextBoxBill) when the user selects New Order (ButtonNewOrder)

3. I managed to get a new line for each order but everytime I select the (ButtonBurger), the menu of the order disappears and only the (Hamburger) is shown in the first line of the (TextboxBill). In other words, if the users select different orders then they select (Hamburger) at the end, all the previous orders disappear and (Hamburger appears in the beginning. (I attached the pictures for clarifying the probelm).

I am totally new in programming and I'm trying to learn as much as I can.
Thank you in advance for any comments / help.

Public Class CashRegister

    Structure MenuItems
        Dim ItemName As String
        Dim ItemCost As Decimal
        Dim Total As Decimal


    End Structure

    Private OrderMenu(6) As MenuItems

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

    End Sub
   
    Private Sub ButtonBurger_Click(sender As System.Object, e As System.EventArgs) Handles ButtonBurger.Click
        Dim TotalCost As Decimal
        OrderMenu(1).ItemName = "Hamburger"
        OrderMenu(1).ItemCost = 4.95
        TotalCost += OrderMenu(1).ItemCost
        LabelCost.Text = TotalCost

        TextBoxBill.Text = OrderMenu(1).ItemName.ToString & vbTab & OrderMenu(1).ItemCost.ToString & vbCrLf

    End Sub
    Private Sub ButtonCheeseburger_Click(sender As System.Object, e As System.EventArgs) Handles ButtonCheeseburger.Click
        Dim TotalCost As Decimal
        OrderMenu(2).ItemName = "Cheeseburger"
        OrderMenu(2).ItemCost = 5.95
        TotalCost += OrderMenu(2).ItemCost
        LabelCost.Text = TotalCost
        TextBoxBill.Text += OrderMenu(2).ItemName.ToString & vbTab & OrderMenu(2).ItemCost.ToString & vbCrLf
    End Sub
    Private Sub ButtonFries_Click(sender As System.Object, e As System.EventArgs) Handles ButtonFries.Click
        Dim TotalCost As Decimal
        OrderMenu(3).ItemName = "Fries"
        OrderMenu(3).ItemCost = 1.99
        TotalCost += OrderMenu(3).ItemCost
        LabelCost.Text = TotalCost
        TextBoxBill.Text += OrderMenu(3).ItemName.ToString & vbTab & vbTab & OrderMenu(3).ItemCost.ToString & vbCrLf
    End Sub

    Private Sub ButtonOnionRings_Click(sender As System.Object, e As System.EventArgs) Handles ButtonOnionRings.Click
        Dim TotalCost As Decimal
        OrderMenu(4).ItemName = "Oinion Rings"
        OrderMenu(4).ItemCost = 2.99
        TotalCost += OrderMenu(4).ItemCost
        LabelCost.Text = TotalCost
        TextBoxBill.Text += OrderMenu(4).ItemName.ToString & vbTab & OrderMenu(4).ItemCost.ToString & vbCrLf
    End Sub

    Private Sub ButtonSoda_Click(sender As System.Object, e As System.EventArgs) Handles ButtonSoda.Click
        Dim TotalCost As Decimal
        OrderMenu(5).ItemName = "Soda"
        OrderMenu(5).ItemCost = 0.99
        TotalCost += OrderMenu(5).ItemCost
        LabelCost.Text = TotalCost
        TextBoxBill.Text += OrderMenu(5).ItemName.ToString & vbTab & vbTab & OrderMenu(5).ItemCost.ToString & vbCrLf
    End Sub

    Private Sub ButtonBeer_Click(sender As System.Object, e As System.EventArgs) Handles ButtonBeer.Click
        Dim TotalCost As Decimal
        OrderMenu(6).ItemName = "Beer"
        OrderMenu(6).ItemCost = 4.99
        TotalCost += OrderMenu(6).ItemCost
        LabelCost.Text = TotalCost
        TextBoxBill.Text += OrderMenu(6).ItemName.ToString & vbTab & vbTab & OrderMenu(6).ItemCost.ToString & vbCrLf
    End Sub

    Private Sub ButtonDone_Click(sender As System.Object, e As System.EventArgs) Handles ButtonDone.Click
        'Adds the total or the order and prints the tax
        Dim Subtotal As Decimal
        Dim Tax As Decimal
        ' Subtotal or the selected order
        ' add tax

    End Sub

    Private Sub ButtonNewOrder_Click(sender As System.Object, e As System.EventArgs) Handles ButtonNewOrder.Click
        'Clears the TexBoxBill and start new order
    End Sub


    Private Sub TextBoxBill_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBoxBill.TextChanged

    End Sub

End Class
Attachments Output2.jpg 47.39 KB

1. Total
You can get total from TotalCost variabel since you already count it TotalCost += OrderMenu(1).ItemCost But you put the declaration in every buttons so you can't use it properly.
You need to put TotalCost in Global Declaration and remove all TotalCost declaration in every buttons.

Private OrderMenu(6) As MenuItems
Dim Dim TotalCost As Decimal
...

You can access it in ButtonDone event : MsgBox(TotalCost) 2. Clear TextBoxBill

Private Sub ButtonNewOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNewOrder.Click
    'Clears the TexBoxBill and start new order
    TextBoxBill.Text = String.Empty
End Sub

3. Hamburger Problem
Your code not complete like others. You missing '+' sign.
Just change this line :

...
TextBoxBill.Text += OrderMenu(1).ItemName.ToString & vbTab & OrderMenu(1).ItemCost.ToString & vbCrLf

Edited 4 Years Ago by Jx_Man: n/a

I know I'm not much of help, but I just have to ask:

How did you manage to figure out structures, string concatenation, special characters (vbTab & vbCrLf) and not know how to clear a textbox or can't figure out that you are clearing whatever existed in textboxbill by not concatenating the new value to the old one?

I know I'm not much of help, but I just have to ask:

How did you manage to figure out structures, string concatenation, special characters (vbTab & vbCrLf) and not know how to clear a textbox or can't figure out that you are clearing whatever existed in textboxbill by not concatenating the new value to the old one?

I meant by clearing the textbox was clearing the 'array' and start from the beginning with new order.
Here in the code that I wrote, every time I clear and start new order, it gives me the total of the "previous" one + the "new order" that I placed.
I'm still figuring out how to do that.

1. Total
You can get total from TotalCost variabel since you already count it TotalCost += OrderMenu(1).ItemCost But you put the declaration in every buttons so you can't use it properly.
You need to put TotalCost in Global Declaration and remove all TotalCost declaration in every buttons.

Private OrderMenu(6) As MenuItems
Dim Dim TotalCost As Decimal
...

You can access it in ButtonDone event : MsgBox(TotalCost) 2. Clear TextBoxBill

Private Sub ButtonNewOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonNewOrder.Click
    'Clears the TexBoxBill and start new order
    TextBoxBill.Text = String.Empty
End Sub

3. Hamburger Problem
Your code not complete like others. You missing '+' sign.
Just change this line :

...
TextBoxBill.Text += OrderMenu(1).ItemName.ToString & vbTab & OrderMenu(1).ItemCost.ToString & vbCrLf

Thank you for your response.
I went through all the suggestions but in the last part, I'm still having problems in 'clearing' the array and start new order.
Yes the command that you provided clears all the strings but when I start new order (ButtonNewOrder) the previous output (TotalItems) is saved and added to the 'New' (TotalItems). I will keep looking for a solution and I will post it with the corrected code if I'm done.

for i = 1 to 6
   OrderMenu(i).ItemName = ""
   OrderMenu(i).ItemCost = 0
next i

Edited 4 Years Ago by ChrisPadgham: n/a

Also TotalCost should be a module level variable declaration. By declaring it in each subroutine, it is created when the subroutine is invoked and destroyed when the subroutine terminates making it useless. Have one

dim TotalCost as Decimal

in the declarations section of the module at the top

Thank you for your response.
I went through all the suggestions but in the last part, I'm still having problems in 'clearing' the array and start new order.
Yes the command that you provided clears all the strings but when I start new order (ButtonNewOrder) the previous output (TotalItems) is saved and added to the 'New' (TotalItems). I will keep looking for a solution and I will post it with the corrected code if I'm done.

ChrisPadgham already answered it. just put that the code in button new order event.

for i = 1 to 6
   OrderMenu(i).ItemName = ""
   OrderMenu(i).ItemCost = 0
next i

Thank you so much for the reply. Your comments were really helpful

ChrisPadgham already answered it. just put that the code in button new order event.

Once again, I appreciate the help and thank you for your comments.

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