Very Busy (VB) Mail Order
Do the housekeeping required to setup your project.
This includes:
- Creating a New Project Directory
- Saving the Form
- Saving the Project File
This is a fairly easy example that makes use of a lookup table. Here is the User Interface:
You must select a weight and a zone from the tables and click the Find Rate button to
calculate the rate. Initialize the accumulator table to hold the shipping charges for each Weight / Zone combination (multi dimensional table) in Form Load Clear will de-select the ListBox controls and blank the charge. Print Summary will display a list of transactions and a total as described below. The Calculate process will use the ListBox indexes to pull the rate out of the lookup table initialized in Form Load. |
This is more or less a dump of the contents to the accumulator array.
This accumulator array will be implemented as a UDT containing the Rate, Zone, and Cost . The UDT and the Arrays will be declare as Public in a Module. Build the report in Form Paint or Form Activate |
Public Variables declared in a project module
Public Type ShippingCharges
strZone As String
strWeight As String
sngRate As Single
End Type
Public m_udtTransaction(20) As ShippingCharges
Public m_intNumberTransactions As Integer
Public m_sngTotalCharges As Single
Public m_sngRate(0 To 4, 0 To 3) As Single
m_sngRate is a 5 by 4 table.
m_udtTransaction(20) contains 20 elements indexed 0
- 19
Build the report in From Paint
Private Sub Form_Paint()
Dim intIndex As Integer
Me.Cls
Me.Print
Me.Print
Me.Font.Name = "Courier New"
Me.Print
Me.Print , "Weight", "Zone", "Price"
Me.Print
If m_intNumberTransactions = 0 Then
Me.ForeColor = vbRed
Me.Print , , "No data to summarize"
Me.ForeColor = vbBlack
Exit Sub
End If
For intIndex = 0 To m_intNumberTransactions - 1
Me.Print , m_udtTransaction(intIndex).strWeight,
_
m_udtTransaction(intIndex).strZone,
_
FormatCurrency(m_udtTransaction(intIndex).sngRate)
Next intIndex
Me.Print
Me.Print , "Total Shipping Charges: ",
FormatCurrency(m_sngTotalCharges)
End Sub
Maintain the accumulators and edit the input in the Find Rate event handler
Private Sub cmdRate_Click()
Dim intWeightSub As Integer
Dim intZoneSub As Integer
intWeightSub = lstWeight.ListIndex
intZoneSub = lstZone.ListIndex
If intWeightSub = -1 Then
MsgBox "Please select the
weight.", vbExclamation, "Missing Data"
Exit Sub
End If
If intZoneSub = -1 Then
MsgBox "Please select the
zone.", vbExclamation, "Missing Data"
Exit Sub
End If
lblShipping.Caption = _
FormatCurrency(m_sngRate(intWeightSub,
intZoneSub))
m_udtTransaction(m_intNumberTransactions).strZone = _
lstZone.List(intZoneSub)
m_udtTransaction(m_intNumberTransactions).strWeight = _
lstWeight.List(intWeightSub)
m_udtTransaction(m_intNumberTransactions).sngRate = _
m_sngRate(intWeightsub,
intZoneSub)
m_intNumberTransactions = m_intNumberTransactions + 1
m_sngTotalCharges = m_sngTotalCharges + _
m_sngRate(intWeightSub,
intZoneSub)
End Sub
This completes the lab