Connecting Tech Pros Worldwide Forums | Help | Site Map

Lunch order application

Newbie
 
Join Date: Oct 2008
Posts: 1
#1: Oct 30 '08
I only manage to do this assignment using combo box anyone has any idea to do this using option box???

Specifications

Create a form based application that resembles the above figure. For each order, the user selects one main course item and zero or more of the associated add-ons. When the user clicks on the Place Order button, the application displays the sub total, tax, and total due for the order. It also enables the Print Receipt button. To print a copy of the lunch order form, the user can click on the Print Receipt button. This also clears the add-on check boxes and resets the Main course option button to Hamburger.

For the three add-ons and prices change based on the main course item that’s selected. For a hamburger, the three items are: (1) Lettuce, tomato, and onions; (2) Mayonnaise and mustard; and (3) French fries. The price of each is 75 cents. For a pizza, the three items are: (1) Pepperoni, (2) Sausage, and (3) Olives. The price of each is 50 cents. For a salad, the three items are the ones shown above and the price of each is 25 cents.
The sub total is equal to the cost of the main course item, plus the cost of the
Add-ons. The tax is the sub total * .0785. And the total due is the sub total + tax. To print a copy of the lunch order form when the user clicks on the Print Receipt button, you can use the PrintForm method of the form object.

Thank you

These are my code
Expand|Select|Wrap|Line Numbers
  1. Const NAME_POS = 0
  2. Const ADDON_PRICE_POS = 1
  3. Const MAIN_PRICE_POS = 2
  4. Const ADDON_ARRAY_POS = 3
  5.  
  6. Const TAX_RATE = 0.0785
  7.  
  8. Dim Products(2, 3) As Variant
  9. Dim HamburgerAddOns(0 To 2) As String
  10. Dim PizzaAddOns(0 To 2) As String
  11. Dim SaladAddOns(0 To 2) As String
  12.  
  13. Private Sub Form_Load()
  14.     InitArrays
  15.     InitCboMainCourse
  16.     ResetForm
  17. End Sub
  18.  
  19. Private Sub InitArrays()
  20.     Products(0, NAME_POS) = "Hamburger"
  21.     Products(1, NAME_POS) = "Pizza"
  22.     Products(2, NAME_POS) = "Salad"
  23.  
  24.     Products(0, ADDON_PRICE_POS) = CCur(0.75)
  25.     Products(1, ADDON_PRICE_POS) = CCur(0.5)
  26.     Products(2, ADDON_PRICE_POS) = CCur(0.25)
  27.  
  28.     Products(0, MAIN_PRICE_POS) = CCur(6.95)
  29.     Products(1, MAIN_PRICE_POS) = CCur(5.95)
  30.     Products(2, MAIN_PRICE_POS) = CCur(4.95)
  31.  
  32.     HamburgerAddOns(0) = "Lettuce, Tomato, and Onions"
  33.     HamburgerAddOns(1) = "Mayonnaise and Mustard"
  34.     HamburgerAddOns(2) = "French fries"
  35.     Products(0, ADDON_ARRAY_POS) = HamburgerAddOns
  36.  
  37.     PizzaAddOns(0) = "Pepperoni"
  38.     PizzaAddOns(1) = "Sausage"
  39.     PizzaAddOns(2) = "Olives"
  40.     Products(1, ADDON_ARRAY_POS) = PizzaAddOns
  41.  
  42.     SaladAddOns(0) = "Croutons"
  43.     SaladAddOns(1) = "Bacon bits"
  44.     SaladAddOns(2) = "Bread stick"
  45.     Products(2, ADDON_ARRAY_POS) = SaladAddOns
  46. End Sub
  47.  
  48. Private Sub InitCboMainCourse()
  49.     Dim i As Integer
  50.  
  51.     For i = LBound(Products, 1) To UBound(Products, 1)
  52.         cboMainCourse.AddItem Products(i, NAME_POS)
  53.     Next
  54. End Sub
  55.  
  56. Private Sub ResetForm()
  57.     cboMainCourse.ListIndex = 0
  58.     cmdPrintReceipt.Enabled = False
  59. End Sub
  60.  
  61. Private Sub cboMainCourse_Click()
  62.     Dim i As Integer
  63.  
  64.     cmdPrintReceipt.Enabled = False
  65.  
  66.     For i = chkAddOn.LBound To chkAddOn.UBound
  67.         chkAddOn(i).Value = vbUnchecked
  68.         chkAddOn(i).Caption = Products(cboMainCourse.ListIndex, ADDON_ARRAY_POS)(i)
  69.     Next
  70. End Sub
  71.  
  72. Private Sub cmdPlaceOrder_Click()
  73.     DisplayReceipt
  74.     cmdPrintReceipt.Enabled = True
  75. End Sub
  76.  
  77. Private Sub cmdPrintReceipt_Click()
  78.     Me.PrintForm
  79.     ResetForm
  80. End Sub
  81.  
  82. Private Sub cmdExit_Click()
  83.     Unload Me
  84. End Sub
  85.  
  86. Private Sub DisplayReceipt()
  87.     Dim curSubTotal As Currency
  88.     Dim curTax As Currency
  89.     Dim intAddOnCount As Integer
  90.     Dim i As Integer
  91.     Dim intSelectedProduct As Integer
  92.  
  93.     intSelectedProduct = cboMainCourse.ListIndex
  94.  
  95.     For i = chkAddOn.LBound To chkAddOn.UBound
  96.         If chkAddOn(i).Value = vbChecked Then
  97.             intAddOnCount = intAddOnCount + 1
  98.         End If
  99.     Next
  100.  
  101.     curSubTotal = CCur(Products(cboMainCourse.ListIndex, MAIN_PRICE_POS) _
  102.      + intAddOnCount * Products(intSelectedProduct, ADDON_PRICE_POS))
  103.  
  104.     curTax = curSubTotal * TAX_RATE
  105.  
  106.     lblSubtotal.Caption = CStr(FormatCurrency(curSubTotal, 2))
  107.     lblTax.Caption = CStr(FormatCurrency(curTax, 2))
  108.     lblTotal.Caption = CStr(FormatCurrency(curSubTotal + curTax, 2))
  109. End Sub

Reply