home *** CD-ROM | disk | FTP | other *** search
- Listing 1 [[VB4]]
-
- ' Removes inventory from the system
- ' This is used when inventory is sold,
- ' damaged, or adjusted
- ' Parameters:
- ' sInvItem Product Number of the
- ' item
- ' iNumRemoved Number of the
- ' product removed from
- ' inventory
- ' Returns:
- ' iTotal Total number in
- ' inventory
- Public Function _
- RemoveInventory(sInvItem As _
- String, iNumRemoved As Integer) As _
- Integer
- Dim iCurrentTotal
-
- ' Retrieve the current inventory
- ' count from the collection
- iCurrentTotal = _
- Me.Item(sInvItem).Quantity
-
- ' Perform the subtraction
- iCurrentTotal = iCurrentTotal - _
- iNumRemoved
-
- ' Code here should ensure the total
- ' number in inventory is never < 0
-
- ' Code here could also check the
- ' reorder point and automatically
- ' reorder when an order point is
- ' reached
-
- ' Update the collection
- Me.Item(sInvItem).Quantity = _
- iCurrentTotal
-
- ' Return the total amount
- RemoveInventory = iCurrentTotal
-
- End Function
-
-
-
- Listing 2 [[vb4]]
-
-
- Private Sub Class_Initialize()
- ' Create the collection of inventory
- ' items
- CollectProducts
- End Sub
-
- ' Fills the collection with the products
- Private Sub CollectProducts()
- ' This is the prototype code
- ' to create the data in the collection
- ' Normally this information would
- ' exist in a database
- Dim Item As New CItem
-
- Item.ProductID = "1"
- Item.ProductNumber = "WD-123"
- Item.ProductName = "Widgets"
- Item.Quantity = 16
-
- ' Add this one to the collection
- ' Using the product number
- ' as the key
- m_colItems.Add Item, _
- Item.ProductNumber
-
- ' Clear the reference
- Set Item = Nothing
-
- ' Set another one
- Item.ProductID = "2"
- Item.ProductNumber = "GG-123"
- Item.ProductName = "Gagets"
- Item.Quantity = 120
-
- ' Add this one to the collection
- ' Using the product number
- ' as the key
- m_colItems.Add Item, _
- Item.ProductNumber
-
- End Sub
-
-
-
- Listing 3 [[VB4]]
-
- ' Form Name: frmInventory
- ' Author: Deborah Kurata, InStep
- ' Technologies
- ' Date: December 10, 1995
- ' Description: Inventory form.
- ' This is a little test form for the OLE
- ' server and NOT a good design for an
- ' inventory form!
- '
- ' Revisions:
- '
- Option Explicit
-
- ' Private member variables
- Private m_Inventory As CInventory
-
- ' Constants for the command butons
- Const iCLOSE = 0
- Const iRECEIVE = 1
- Const iSELL = 2
-
- Private Sub cboItems_Click()
- ' If the user selects an item
- ' clear the number received
- txtReceived.Text = ""
-
- ' Set the total in inventory as
- ' appropriate
- If cboItems.ListIndex <> -1 Then
- txtTotal.Text = m_Inventory.Item_
- (cboItems.ListIndex + _
- 1).Quantity
- End If
-
- ' Ensure the button is disabled
- ' until a quantity is entered
- cmdInventory(iRECEIVE).Enabled = _
- False
- cmdInventory(iSELL).Enabled = False
- End Sub
-
- Private Sub cmdInventory_Click(Index _
- As Integer)
- Dim iTotal As Integer
- Dim sProductNumber As String
-
- Select Case Index
-
- Case iCLOSE
- Unload Me
-
- Case iRECEIVE
- ' Product number for the
- ' inventory item
- ' NOTE: combo's are 0 based,
- ' collections are 1 based
- sProductNumber = _
- m_Inventory.Item_
- (cboItems.ListIndex + _
- 1).ProductNumber
-
- ' Add the defined amount to
- ' the inventory
- iTotal = m_Inventory._
- AddInventory_
- (sProductNumber, _
- Val(txtReceived.Text))
- If Err.Number <> 0 Then
- ' A more friendly error
- ' message would be
- ' displayed to the user
- ' here
- ' With a more detailed
- ' message printed to a
- ' log file
- MsgBox Err.Description
- End If
-
- ' Display the revised
- ' inventory amount on the
- ' screen
- txtTotal.Text = iTotal
-
- Case iSELL
- ' Product number for the
- ' inventory item
- ' NOTE: combo's are 0 based,
- ' collections are 1 based
- sProductNumber = _
- m_Inventory.Item_
- (cboItems.ListIndex + _
- 1).ProductNumber
-
- ' Remove the defined amount
- ' from the inventory
- iTotal = _
- m_Inventory._
- RemoveInventory_
- (sProductNumber, _
- Val(txtReceived.Text))
- If Err.Number <> 0 Then
- ' A more friendly error
- ' message would be
- ' displayed to the user
- ' here
- ' With a more detailed
- ' message printed to a
- ' log file
- MsgBox Err.Description
- End If
-
- ' Display the revised
- ' inventory amount on the
- ' screen
- txtTotal.Text = iTotal
- End Select
- End Sub
-
- Private Sub Form_Load()
- Dim colItems As New Collection
- Dim lCount As Long
-
- ' Create only one instance of the
- ' inventory class
- Set m_Inventory = New CInventory
- If Err.Number <> 0 Then
- ' A more friendly error message
- ' would be displayed to the user
- ' here
- ' With a more detailed message
- ' printed to a log file
- MsgBox Err.Description
- Unload Me
- GoTo EXIT_Form_Load
- End If
-
- ' Fill the combo box with values
- For lCount = 1 To m_Inventory.Count
- With m_Inventory.Item(lCount)
- cboItems.AddItem _
- .ProductNumber & _
- Space(5) & .ProductName
- End With
- Next lCount
-
- EXIT_Form_Load:
- End Sub
-
- Private Sub Form_Unload(Cancel As _
- Integer)
- ' Clear the instance
- Set m_Inventory = Nothing
- End Sub
-
- Private Sub txtReceived_Change()
- ' If there is an amount entered and
- ' the command button is disabled,
- ' enable it
- If txtReceived.Text <> "" And _
- cmdInventory(iRECEIVE).Enabled _
- = False Then
- cmdInventory(iRECEIVE).Enabled _
- = True
- cmdInventory(iSELL).Enabled _
- = True
- End If
- End Sub
-
- Private Sub _
- txtReceived_KeyPress(KeyAscii _
- As Integer)
- If (Chr$(KeyAscii) <> vbBack) And _
- (Not IsNumeric(Chr$(KeyAscii))) _
- Then
- Beep
- KeyAscii = 0
- End If
- End Sub
-
- Prog w/Class Listings March 1996 page 5
-
-
-