' Ch08ActiveXExeServer
' code for frmDispensaryItem.frm
Option Explicit
Private mDispensaryItems As New CDispensaryItems 'Instantiate the collection
Private Sub cmdAdd_Click()
'Add an item to the collection
If cboFrameSize.ListIndex <> -1 And cboFrameStyle.ListIndex <> -1 Then
mDispensaryItems.Add cboFrameStyle.ListIndex + 1, _
cboFrameSize.ListIndex + 1, _
Val(txtQuantity.Text)
Else
MsgBox "Enter values for the item.", vbInformation, "Dispensary Items"
End If
cmdClear_Click 'Clear out form controls
End Sub
Private Sub cmdClear_Click()
'Clear screen controls
cboFrameSize.ListIndex = -1
cboFrameStyle.ListIndex = -1
txtQuantity.Text = ""
picDisplay.Cls
End Sub
Private Sub cmdCount_Click()
'Display the number of objects in the collection
Dim strMsg As String
strMsg = "The number of Dispensary Items is " & mDispensaryItems.Count
MsgBox strMsg, vbInformation, "AVB Dispensary Items"
End Sub
Private Sub cmdDisplay_Click()
'Display the objects in the collection
Dim DisplayItem As CDispensaryItem
picDisplay.Cls 'Clear the display and print headings
picDisplay.Print "Item Code", "Frame Style", "Frame Size", "Quantity"
picDisplay.Print
For Each DisplayItem In mDispensaryItems
With DisplayItem
picDisplay.Print .DispensaryItemCode, .FrameStyle, .FrameSize, _
.Quantity
End With
Next
End Sub
Private Sub cmdDisplayItem_Click()
'Display one item from collection
Dim strKey As String
On Error GoTo HandleError
strKey = InputBox("Enter item code to display.", "Display Dispensary Item")
picDisplay.Cls 'Clear the display and print headings
picDisplay.Print "Item Code", "Frame Style", "Frame Size", "Quantity"
picDisplay.Print
With mDispensaryItems(strKey)
picDisplay.Print .DispensaryItemCode, .FrameSize, .FrameStyle, .Quantity
End With
cmdRemove_Click_Exit:
Exit Sub
HandleError:
If Err.Number = diItemCodeError Then
MsgBox "Invalid Dispensary Item Code", vbInformation, _
"Display Dispensary Item"
Else
MsgBox "Unexpected Error", vbInformation, "Display Dispensary Item"
End If
End Sub
Private Sub cmdRemove_Click()
'Remove an item
Dim strKey As String
On Error GoTo HandleError
strKey = InputBox("Enter item code to remove.", "Remove Dispensary Item")
mDispensaryItems.Remove strKey
cmdRemove_Click_Exit:
Exit Sub
HandleError:
If Err.Number = diItemCodeError Then
MsgBox "Invalid Dispensary Item Code", vbInformation, _
"Remove Dispensary Item"
Else
MsgBox "Unexpected Error", vbInformation, "Display Dispensary Item"
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Release object variables
Set mDispensaryItems = Nothing
End Sub
Private Sub mnuFileClose_Click()
'Exit the project
Unload Me
End Sub