CD Publisher


In this exercise, we will develop an application for a small CD publishing company. The owner wants the prices to be calculated so a customer would get a discount if he orders more. To attract customers and encourage them to order more, she has decided to fix the prices so that the customer would pay:

  • $20/CD if she orders less than 20 units
  • $15/CD if she orders less than 50 units
  • $12/CD if she orders less than 100 units
  • $8/CD if she orders less than 500 units
  • $5/CD if she orders more than 500 units
  1. Start Microsoft Visual Basic and create a Standard EXE application
  2. Save the application in a new folder named CD Publisher
  3. Save the form as frmMain and save the project as CDPublisher
  4. To use the needed spin button, on the main menu, click Project -> Components...
  5. In the Components dialog box, click the Microsoft Windows Common Controls 6.0 (SP4) check box
  6. Click OK
  7. Design it as follows:
    Control Properties
    Form Name: frmMain
    Border Style: 3 - FixedDialog
    Caption: CD Publisher
    Label Caption: Number of CDs:
    TextBox Name: txtQuantity
    Alignment: 1 - Right Justify
    UpDown Name: updQuantity
    Alignment: 1
    Buddy Control: txtQuantity
    Max: 10000
    Label Caption: Unit Price:
    TextBox Name: txtUnitPrice
    Alignment: 1 - Right Justify
    Label Caption: Total Price:
    TextBox Name: txtTotalPrice
    Alignment: 1 - Right Justify
    CommandButton Name: cmdClose
    Caption: Close
  8. Double-click the Close button and implement its Click event as follows:
    Private Sub cmdClose_Click()
    End Sub
  9. Double-click the UpDown control and implement its Change event as follows:
    Private Sub updQuantity_Change()
        Dim Quantity As Integer
        Dim UnitPrice, TotalPrice As Currency
        Quantity = CInt(txtQuantity.Text)
        If Quantity < 20 Then
            UnitPrice = 20
        ElseIf Quantity < 50 Then
            UnitPrice = 15
        ElseIf Quantity < 100 Then
            UnitPrice = 12
        ElseIf Quantity < 500 Then
            UnitPrice = 8
            UnitPrice = 5
        End If
        TotalPrice = Quantity * UnitPrice
        txtUnitPrice.Text = CStr(UnitPrice)
        txtTotalPrice.Text = CStr(TotalPrice)
    End Sub
  10. To allow the user to enter a quantity value, access the LostFocus event of the txtQuantity text box and implement it as follows:
    Private Sub txtQuantity_LostFocus()
    End Sub
  11. Test the application

Home Copyright 2004-2014 FunctionX, Inc.