Lunch order application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Xiaode
    New Member
    • Oct 2008
    • 1

    Lunch order application

    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
    Code:
    Const NAME_POS = 0
    Const ADDON_PRICE_POS = 1
    Const MAIN_PRICE_POS = 2
    Const ADDON_ARRAY_POS = 3
    
    Const TAX_RATE = 0.0785
    
    Dim Products(2, 3) As Variant
    Dim HamburgerAddOns(0 To 2) As String
    Dim PizzaAddOns(0 To 2) As String
    Dim SaladAddOns(0 To 2) As String
    
    Private Sub Form_Load()
        InitArrays
        InitCboMainCourse
        ResetForm
    End Sub
    
    Private Sub InitArrays()
        Products(0, NAME_POS) = "Hamburger"
        Products(1, NAME_POS) = "Pizza"
        Products(2, NAME_POS) = "Salad"
        
        Products(0, ADDON_PRICE_POS) = CCur(0.75)
        Products(1, ADDON_PRICE_POS) = CCur(0.5)
        Products(2, ADDON_PRICE_POS) = CCur(0.25)
        
        Products(0, MAIN_PRICE_POS) = CCur(6.95)
        Products(1, MAIN_PRICE_POS) = CCur(5.95)
        Products(2, MAIN_PRICE_POS) = CCur(4.95)
        
        HamburgerAddOns(0) = "Lettuce, Tomato, and Onions"
        HamburgerAddOns(1) = "Mayonnaise and Mustard"
        HamburgerAddOns(2) = "French fries"
        Products(0, ADDON_ARRAY_POS) = HamburgerAddOns
        
        PizzaAddOns(0) = "Pepperoni"
        PizzaAddOns(1) = "Sausage"
        PizzaAddOns(2) = "Olives"
        Products(1, ADDON_ARRAY_POS) = PizzaAddOns
        
        SaladAddOns(0) = "Croutons"
        SaladAddOns(1) = "Bacon bits"
        SaladAddOns(2) = "Bread stick"
        Products(2, ADDON_ARRAY_POS) = SaladAddOns
    End Sub
    
    Private Sub InitCboMainCourse()
        Dim i As Integer
        
        For i = LBound(Products, 1) To UBound(Products, 1)
            cboMainCourse.AddItem Products(i, NAME_POS)
        Next
    End Sub
    
    Private Sub ResetForm()
        cboMainCourse.ListIndex = 0
        cmdPrintReceipt.Enabled = False
    End Sub
    
    Private Sub cboMainCourse_Click()
        Dim i As Integer
        
        cmdPrintReceipt.Enabled = False
        
        For i = chkAddOn.LBound To chkAddOn.UBound
            chkAddOn(i).Value = vbUnchecked
            chkAddOn(i).Caption = Products(cboMainCourse.ListIndex, ADDON_ARRAY_POS)(i)
        Next
    End Sub
    
    Private Sub cmdPlaceOrder_Click()
        DisplayReceipt
        cmdPrintReceipt.Enabled = True
    End Sub
    
    Private Sub cmdPrintReceipt_Click()
        Me.PrintForm
        ResetForm
    End Sub
    
    Private Sub cmdExit_Click()
        Unload Me
    End Sub
    
    Private Sub DisplayReceipt()
        Dim curSubTotal As Currency
        Dim curTax As Currency
        Dim intAddOnCount As Integer
        Dim i As Integer
        Dim intSelectedProduct As Integer
        
        intSelectedProduct = cboMainCourse.ListIndex
        
        For i = chkAddOn.LBound To chkAddOn.UBound
            If chkAddOn(i).Value = vbChecked Then
                intAddOnCount = intAddOnCount + 1
            End If
        Next
        
        curSubTotal = CCur(Products(cboMainCourse.ListIndex, MAIN_PRICE_POS) _
         + intAddOnCount * Products(intSelectedProduct, ADDON_PRICE_POS))
         
        curTax = curSubTotal * TAX_RATE
            
        lblSubtotal.Caption = CStr(FormatCurrency(curSubTotal, 2))
        lblTax.Caption = CStr(FormatCurrency(curTax, 2))
        lblTotal.Caption = CStr(FormatCurrency(curSubTotal + curTax, 2))
    End Sub
Working...