Lab for Week 7 - Step by Step

 

Very Busy (VB) Mail Order

Do the housekeeping required to setup your project.

This includes:

In addition to the main module, there are three additional forms and a module so add these components and save the project so that all of the pieces are properly named and are stored in the project directory.


Specifications

This program will generate invoices for each customer, detailing each item selected. The program will ask for customer information and start a new invoice. Note that the customer information is disabled until the invoice is completed or cancelled. Disabling the Frame effects all of the customer information. Proceed with the selection of each item. At anytime you can display a summary of the invoice, but printing the form will close the order. You can also Cancel the order, which also completes the invoice, but marks it cancelled.

Lab

 

The main form contains a number of TextBoxes. These controls are edited in the various Command Button event handlers, but there is no code tied directly to any of these controls.This is also true of the Catalog ComboBox. This control is initialized at design time and will contain the following entries:

Odds and Ends
Solutions
Camping Needs
ToolTime
Spiegel
The Outlet
The Large Size

Requesting a new invoice expects that the customer information has been entered. The TextBoxes are edited to make sure SOMETHING is present, and if so, begin the new invoice and enable the item selection portion of the form.

Private Sub cmdNewInvoice_Click()

If txtName.Text = "" Or txtStreet.Text = "" Or txtCity.Text = "" _
                                    Or txtState.Text = "" Or txtZip.Text = "" Then
        MsgBox "Please enter all of the customer information.", _
                            vbOKOnly, "Input Needed"
        txtName.SetFocus
        Exit Sub
End If

PrintInvoiceHeadings

cmdNewInvoice.Enabled = False
fraCustomer.Enabled = False

fraItem.Enabled = True
cmdDisplayInvoice.Enabled = True
cmdAdd.Enabled = True
cmdCancelOrder.Enabled = True

End Sub

Adding an item to the invoice involves editing the input fields and then calling the Utility Procedures to complete the Item Add resuest. Here are the Utility Procedures:

Private Sub CalculateItem()

Dim intQuantity As Integer
Dim intWeightValue As Integer
Dim sngPrice As Single
Dim sngItemAmount As Single
Dim strFormattedExtPrice As String
Dim strFormattedPrice As String

intQuantity = Val(txtQuantity.Text)
intWeightValue = Val(txtWeight.Text)
sngPrice = Val(txtPrice.Text)

sngItemAmount = intQuantity * sngPrice

m_sngTotalWeight = m_sngTotalWeight + (intQuantity * intWeightValue)
m_sngTotalAmountDue = m_sngTotalAmountDue + sngItemAmount

strFormattedExtPrice = FormatCurrency(sngItemAmount)
strFormattedPrice = FormatCurrency(sngPrice)
Printer.Print _
    Tab(6); cboCatalog.Text; _
    Tab(21); txtDescription.Text; _
    Tab(43 - Len(txtQuantity.Text)); txtQuantity.Text; _
    Tab(52 - Len(strFormattedPrice)); strFormattedPrice; _
    Tab(62 - Len(strFormattedExtPrice)); strFormattedExtPrice

End Sub

Private Sub ClearOrderControls()

cboCatalog.ListIndex = -1
cboCatalog.Text = ""
txtDescription.Text = ""
txtQuantity.Text = ""
txtWeight.Text = ""
txtPrice.Text = ""

End Sub

The DisplayInvoice Button performs some calculations and sets some frmSummary public variables before passing control to the summary form.

Private Sub cmdDisplayInvoice_Click()

Dim sngShipAndHandleTotal As Single
Dim sngTax As Single
Dim sngFinalTotal As Single
Const sngTaxRate As Single = 0.08

frmSummary.lblName.Caption = txtName.Text
frmSummary.lblAddress.Caption = txtStreet.Text
frmSummary.lblCityStateZip = _
txtCity.Text & ", " & _
txtState.Text & " " & _
txtZip.Text

With frmSummary
    .lblAmountDue.Caption = FormatCurrency(m_sngTotalAmountDue)

    'Calculate the tax for this order
    If UCase(txtState.Text) = "CA" Then
        sngTax = m_sngTotalAmountDue * sngTaxRate
    End If
    .lblSalesTax.Caption = FormatCurrency(sngTax)
    .lblSubtotal.Caption = _
    FormatCurrency(m_sngTotalAmountDue + sngTax)

    sngShipAndHandleTotal = sngCalcShipHandle(m_sngTotalWeight)
    .lblShipping.Caption = FormatCurrency(sngShipAndHandleTotal)
    .lblTotalDue.Caption = _
            FormatCurrency(m_sngTotalAmountDue + sngTax + sngShipAndHandleTotal)
End With

frmSummary.Show vbModal

End Sub

Cancelling and invoice will close out the print job by writing Cancelled on the invoice and closing the document. The process double checks to make sure that this is really what you wanted to do, and also prepares for a new customer invoice.

Private Sub cmdCancelOrder_Click()

Dim intResponse As Integer

intResponse = _
    MsgBox("Are you sure you want to cancel this order?", _
                    vbYesNo, _
                        "Response Required")

If intResponse = vbNo Then
    Exit Sub
End If

Printer.Print
Printer.Print
Printer.Print , , "ORDER CANCELLED"
Printer.EndDoc

ClearForm

cmdNewInvoice.Enabled = True
fraCustomer.Enabled = True

fraItem.Enabled = False
cmdAdd.Enabled = False
cmdDisplayInvoice.Enabled = False
cmdCancelOrder.Enabled = False

End Sub

 

Lab

The code associated with this form is all tied to the Print Button. It's function is to complete the order, and reset the controls on the main form to prepare for the next customer invoice.

Private Sub cmdPrint_Click()
    Printer.Print
    Printer.Print
    Printer.Print Tab(30); "Total Price";
    Printer.Print Tab(62 - Len(lblAmountDue.Caption)); lblAmountDue.Caption
    Printer.Print Tab(30); "Tax";
    Printer.Print Tab(62 - Len(lblSalesTax.Caption)); lblSalesTax.Caption
    Printer.Print Tab(30); "Shipping and Handling";
    Printer.Print Tab(62 - Len(lblShipping.Caption)); lblShipping.Caption
    Printer.Print Tab(30); "Total Due";
    Printer.Print Tab(62 - Len(lblTotalDue.Caption)); lblTotalDue.Caption
    Printer.EndDoc

    With frmMain
        .mnuFileCatalogList.Enabled = True
        .fraCustomer.Enabled = True
        .cmdNewInvoice.Enabled = True
        .fraItem.Enabled = False
        .cmdNewInvoice.Enabled = True
        .cmdAdd.Enabled = False
        .cmdDisplayInvoice.Enabled = False
        .cmdCancelOrder.Enabled = False
    End With

    ClearSummaryForm

    frmSummary.Hide
    frmMain.Show

End Sub

Private Sub ClearSummaryForm()
    lblName.Caption = ""
    lblAddress.Caption = ""
    lblCityStateZip.Caption = ""
    lblAmountDue.Caption = ""
    lblSalesTax.Caption = ""
    lblSubtotal.Caption = ""
    lblShipping.Caption = ""
    lblTotalDue.Caption = ""

End Sub


The code for the About form is trivial. Simply Show the Form:

    frmAbout.Show vbModal


This is the entire contents of modMain. It drives the Splash Screen followed by the start of frmMain.

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Main()
    Splash frmMain, frmSplash, 3

End Sub

Private Sub Splash(MainForm As Form, SplashForm As Form, Time As Integer)
    Load SplashForm
    SplashForm.Show
    SplashForm.Refresh

    Load MainForm
    Sleep Time * 1000
    Unload SplashForm

    MainForm.Show

End Sub


The Project Properties should have Sub Main() as the StartUp Object


This completes the lab

Back to Week 7