So I have created a menu form in VB, which asks user to select items from the menu and then uses the prices to calculate the total. For this I have created 2 lists, one of which is in the main form:
Dim menu As New List(Of MenuItem) From
{
New MenuItem With {.Name = "Burger", .Cost = 2.0 * txtburger.Text},
New MenuItem With {.Name = "wrap", .Cost = 2.0 * txtwrap.Text},
New MenuItem With {.Name = "Parmesan", .Cost = 2.5 * txtparmesan.Text},
New MenuItem With {.Name = "Stirfry", .Cost = 3.0 * txtstirfry.Text},
New MenuItem With {.Name = "pitta", .Cost = 2.5 * txtpitta.Text},
New MenuItem With {.Name = "bundle", .Cost = 6.0 * txtbundle.Text},
This list uses a 'MenuItem' class to create items in the menu and set their prices.
The second list is in the 'order' class:
Public Property Items As List(Of MenuItem) = New List(Of MenuItem)
Public Sub AddItem(ByVal item As MenuItem)
Items.Add(item)
End Sub
This class uses an 'AddItem' method to add items from the full menu previously defined, into this list. The items added to this list here are the items which the user will select when the form is loaded.
But How do I instantiate an object in 'order' class, so the items that the user chooses get added to this list from the main form? Each item has a text box next to it in the form which determines the quantity of the item. So I will have to pass in a parameter for each item that gets selected. I'm not really sure how to do this.
Hope all this makes sense and I'm doing it right.