PDA

View Full Version : VB Help



The_Doctor
02-18-2006, 17:13
I am in the middle of making a food ordering system for my college project.

Most of it is working great. There are some problems that I need help with.

On the food ordering screen the user clicks a button to open a menu (eg cmdChips opens frmChips) and selects the item and the quantity that the customer wants. The item and quantity appear in a list box (lstItems) (eg small chips x2) and the price appears in a list box (lstPrice) next to it. underneath the list boxes there is a text box that contains the total (txtTotal).

When users clicks on one of the items it is removed from the list an appears in another list box (lstDeletedItems). The price is also moved to another list box (lstDeletedPrice). This is where thing fall apart. The price that is removed is always the one at the top of the list. I think it is something to do with list count or list index.

The sample code I have is for the same set up, only the items and price appear in one list box not two.

Then there is a problem with recalculating the total price.

This is the code I have right now. This is from one of the menus:

Private Sub cmdAdd_Click()
Quantity = cmbQuantity.Text
frmFoodOrdering.lstItems.AddItem ItemName & " " & "x" & Quantity
LineCost = ItemCost * Quantity
frmFoodOrdering.lstPrice.AddItem LineCost
TotalCost = TotalCost + LineCost
frmFoodOrdering.txtTotal = TotalCost
End Sub

Private Sub cmdBurger_Click()
txtSelection = "Burger"
ItemName = txtSelection
ItemCost = "0.99"
End Sub

Private Sub cmdCheeseburger_Click()
txtSelection = "Cheeseburger"
ItemName = txtSelection
ItemCost = "1.50"
End Sub

Private Sub cmdClose_Click()
frmBurgers.Hide
End Sub

Private Sub cmdDoubleBurger_Click()
txtSelection = "Double Burger"
ItemName = txtSelection
ItemCost = "1.50"
End Sub

Private Sub cmdDoubleBurgerWithCheese_Click()
txtSelection = "Double Burger with Cheese"
ItemName = txtSelection
ItemCost = "2.00"
End Sub

Private Sub cmdHelp_Click()
frmBurgersHelp.Show
End Sub

Private Sub lstItem_Click()
ItemName = lstItem
End Sub

Private Sub cmdQuarterPounder_Click()
txtSelection = "Quarter Pounder"
ItemName = txtSelection
ItemCost = "1.30"
End Sub

Private Sub cmdQuarterPounderWithCheese_Click()
txtSelection = "Quarter Pounder with Cheese"
ItemName = txtSelection
ItemCost = "1.80"
End Sub

And this is from the main food ordering screen, the last two section are where the problems are:

Private Sub cmdBurger_Click()
frmBurgers.Show
End Sub

Private Sub cmdCalculator_Click()
frmCalculator.Show
End Sub

Private Sub cmdChips_Click()
frmChips.Show
End Sub

Private Sub cmdDessert_Click()
frmDessert.Show
End Sub

Private Sub cmdFizzyDrinks_Click()
frmFizzyDrinks.Show
End Sub

Private Sub cmdHelp_Click()
frmFoodOrderingHelp.Show
End Sub

Private Sub cmdLogOut_Click()
frmFoodOrdering.Hide
FrmLogin.Show
FrmLogin.txtUsername = ""
FrmLogin.txtPassword = ""
FrmLogin.txtUsername.SetFocus
txtOrdersCompleted.Text = 0
cmdReceipt.Enabled = False
End Sub

Private Sub cmdOrderComplete_Click()
txtOrdersCompleted.Text = txtOrdersCompleted + 1
End Sub

Private Sub cmdOtherDrinks_Click()
frmOtherDrinks.Show
End Sub

Private Sub cmdOtherFood_Click()
frmOtherFood.Show
End Sub

Private Sub cmdReceipt_Click()
'frmReceipt.PrintForm
cmdOrderComplete.Enabled = True
End Sub

Private Sub cmdStillDrinks_Click()
frmStillDrinks.Show
End Sub

Private Sub lstDeletedItems_Click()
Dim DeletedNumber As Integer

lstDeletedItems.RemoveItem lstDeletedItems.ListIndex
lstItems.AddItem lstDeletedItems.List(DeletedNumber)

lstDeletedPrice.RemoveItem lstDeletedPrice.List(DeletedNumber)
lstPrice.AddItem lstDeletedPrice.List(DeletedNumber)
End Sub

Private Sub lstItems_Click()
Dim DeleteCount As Integer
Dim DeletedNumber As Integer
Dim NewPrice As Currency
TotalCost = 0


lstItems.RemoveItem lstItems.ListIndex
lstDeletedItems.AddItem lstItems.List(DeletedNumber)

DeletedNumber = lstItems.ListCount

lstPrice.RemoveItem DeletedNumber
lstDeletedPrice.AddItem lstPrice.List(DeletedNumber)

For DeleteCount = 0 To lstPrice.ListCount - 1 Step 1
NewPrice = Val(Right(lstPrice.List(DeleteCount), 2))
TotalCost = TotalCost + NewPrice
Next DeleteCount
frmFoodOrdering.txtTotal.Text = TotalCost

End Sub

I am not sure what the bit in bold does. I copied it from the sample program and changed a few names.