Question Cost for items in listbox and display list box in another form

pc10015

Member
Joined
Mar 25, 2013
Messages
5
Programming Experience
1-3
I'm making a school project where i have to make a program which allows the user to choose the different sort of pizza's they want. I have to use an array so how can i get the list of pizza's in listbox1 and the selection made will be displayed in listbox2. In listbox1 the first five will cost $5 and the rest will cost $10. After i choose which pizzas i want, i want it to show the total cost of pizza's in a textbox on the same form. The maximum pizza's you can choose is 5. Once i'm done how can i get it to display listbox2 on another form. Help me PLEASE
 
Last edited:
You might try asking one question at a time rather than asking us how to do your whole assignment. What have you got so far and exactly what are you stuck on right now? Once that's addressed then you can continue to do as much more as you can for yourself and then ask about whet you next get stuck on. It's no wonder that you can't get going if you are trying to think several steps ahead when you can't get the first step solved.
 
single question

You might try asking one question at a time rather than asking us how to do your whole assignment. What have you got so far and exactly what are you stuck on right now? Once that's addressed then you can continue to do as much more as you can for yourself and then ask about whet you next get stuck on. It's no wonder that you can't get going if you are trying to think several steps ahead when you can't get the first step solved.
So far i have managed to list the pizza's using Arrays in listbox1 and what i'm doing is putting selected items in listbox2. But what i want to know is that how can i assign cost of $5 to the first 7 pizza's in the list and $10 to the rest of the pizza's in the list, also a way to display the total cost for selected items.
 
Last edited:
You could use two parallel arrays, one for the name of the pizza, and one for the cost. Otherwise, use an If block to assign the cost of the pizza according to its name. Accumulate the total inside the block, for each selected item. However, it doesn't make any sense to assign the value of $5 to the first 5 and $10 to the rest. You will have to post your code.
 
My code so far

You could use two parallel arrays, one for the name of the pizza, and one for the cost. Otherwise, use an If block to assign the cost of the pizza according to its name. Accumulate the total inside the block, for each selected item. However, it doesn't make any sense to assign the value of $5 to the first 5 and $10 to the rest. You will have to post your code.



Public Class Pick_Up_Pizza_Options
Public Pizza() As String = {"BBQ Meatlovers", "Supreme", "Double Bacon Cheeseburger", "Godfather", "Firebreather", "Blue Cheese & Bacon", "Vegorama", "Bangers & Beef", "Champagne Ham & Cheese", "Hawaiian", "Pepperoni", "Simply Cheese", "Beef & Onion", "Veg Trio"}

Private Sub Pick_Up_Pizza_Options_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListOfPizza1.Items.AddRange(Pizza)
End Sub

This is a Add button to add pizza from listbox1 to listbox 2
Private Sub Add1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add1.Click
CustomerSelectedPizza.Items.Add(ListOfPizza1.Text)
CustomerSelectedPizza.SelectedIndex = CustomerSelectedPizza.SelectedIndex + 1


If CustomerSelectedPizza.SelectedIndex > 5 Then
CustomerSelectedPizza.Items.Remove(CustomerSelectedPizza.Text)
End If


'Declare the variables that are constant'
Const fee_1 As Double = 8.5
Const fee_2 As Double = 13.5
'Declaring a variable to use for calculation, this has a starting value of 3'
Dim sum As Double = 3



If CustomerSelectedPizza.SelectedIndex = 0 Then
sum += fee_1
End If
If CustomerSelectedPizza.SelectedIndex = 1 Then
sum += fee_1
End If
If CustomerSelectedPizza.SelectedIndex = 2 Then
sum += fee_1
End If
If CustomerSelectedPizza.SelectedIndex = 3 Then
sum += fee_1
End If
If CustomerSelectedPizza.SelectedIndex = 4 Then
sum += fee_1
End If
If CustomerSelectedPizza.SelectedIndex = 5 Then
sum += fee_2
End If
If CustomerSelectedPizza.SelectedIndex = 6 Then
sum += fee_2
End If
If CustomerSelectedPizza.SelectedIndex = 7 Then
sum += fee_2
End If
If CustomerSelectedPizza.SelectedIndex = 8 Then
sum += fee_2
End If
If CustomerSelectedPizza.SelectedIndex = 9 Then
sum += fee_2
End If
If CustomerSelectedPizza.SelectedIndex = 10 Then
sum += fee_2
End If
If CustomerSelectedPizza.SelectedIndex = 11 Then
sum += fee_2
End If
If CustomerSelectedPizza.SelectedIndex = 12 Then
sum += fee_2
End If
If CustomerSelectedPizza.SelectedIndex = 13 Then
sum += fee_2
End If
If CustomerSelectedPizza.SelectedIndex = 14 Then
sum += fee_2
End If
'This code puts a $ infront of the total cost of pizzas.'
TotalCost.Text = sum.ToString("C")
End Sub

'This remove button will remove one pizza at a time from listbox2 if not needed.'
Private Sub Remove1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Remove1.Click
CustomerSelectedPizza.Items.Remove(CustomerSelectedPizza.Text)
End Sub
'This will clear the whole of listbox2'
Private Sub Clear1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear1.Click
CustomerSelectedPizza.Items.Clear()
TotalCost.Text = 3
End Sub


'This is submit button to move onto next form after completing selection'
Private Sub Submit1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.Click

End Sub


Private Sub CustomerSelectedPizza_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerSelectedPizza.SelectedIndexChanged

End Sub
End Class
 
Why do you have so many If blocks when you can simply do this:

If CustomerSelectedPizza.SelectedIndex <= 4 Then
sum += fee_1
Else
sum += fee_2
End If
 
Why do you have so many If blocks when you can simply do this:

If CustomerSelectedPizza.SelectedIndex <= 4 Then
sum += fee_1
Else
sum += fee_2
End If

Thank you but it still doesn't add cost for each selected pizza, it only shows the price of the first pizza that was selected from the list. The maximum pizzas that you are allowed to select is 5. How can i do this using double arrays?
 
Last edited:
Put it inside a For-Next loop:

For x As Integer = 1 to listbox2.Items.Count
If CustomerSelectedPizza.SelectedIndex <= 4 Then
sum += fee_1
Else
sum += fee_2
End If
Next
 
Put it inside a For-Next loop:

For x As Integer = 1 to listbox2.Items.Count
If CustomerSelectedPizza.SelectedIndex <= 4 Then
sum += fee_1
Else
sum += fee_2
End If
Next
I fixed the problem of the maximum number of pizza allowed to 5 with this code.
If CustomerSelectedPizza.SelectedIndex > 4 Then
MsgBox("Please select 5 Pizzas")
CustomerSelectedPizza.Items.Remove(CustomerSelectedPizza.Text)
End If

But this code still not adding the total cost of those selected pizzas. By the way i am displaying the Total cost in a label, it should change to the new total cost of items in listbox 2(also know as "CustomerSelectedPizza') as i add different pizzas 1 by 1.
If CustomerSelectedPizza.SelectedIndex <= 4 Then
sum += fee_1
Else
sum += fee_2
End If
 
Last edited:
The For-Next loop includes an accumulator (the sum) that should give you the total. You need to display that total in your textbox.

All I did was provide you with a shortcut for part of your code.

I think it's time you worked out your own solution instead of expecting someone else to spoon-feed it to you, step by step.
 
Last edited:
Back
Top