'Project: CreateObject (see pp. 260-262) 'Programmer: Mr. Minich 'Date: April 10, 2001 'Description: Create (instantiate) an object of CDispensary class. Option Explicit Private WithEvents mDispensaryItem As CDispensaryItem 'Instantiate the new object Private Sub Form_Load() 'Instantiate the object Set mDispensaryItem = New CDispensaryItem End Sub Private Sub mDispensaryItem_LowQuantity() 'Display a message to the user Dim strMsg As String strMsg = "The quantity of this item is below the reorder point." MsgBox strMsg, vbInformation, "AVB Dispensary Item" End Sub ' ***** code above is new to this version of the project ******* ' ************************************************************** Private Sub cmdSetProperties_Click() 'Assign form control values to properties of object If cboFrameSize.ListIndex <> -1 And cboFrameStyle.ListIndex <> -1 Then With mDispensaryItem .FrameSize = cboFrameSize.ListIndex + 1 'Save size number .FrameStyle = cboFrameStyle.ListIndex + 1 'Save style number .Quantity = Val(txtQuantity.Text) End With Else MsgBox "Enter values for object properties.", vbInformation, "Advanced Vision" End If End Sub Private Sub cmdAdd_Click() 'Add the object's quantity Dim intNewAmount As Integer intNewAmount = Val(InputBox("How many?", "AVB Dispensary Item Shipment")) mDispensaryItem.ReceiveItem intNewAmount 'Call the object's method txtQuantity.Text = mDispensaryItem.Quantity 'Display the updated quantity End Sub Private Sub cmdClearProperties_Click() 'Assign blanks to object property values mDispensaryItem.ClearProperties End Sub Private Sub cmdDisplay_Click() 'Display object properties in a message box Dim strMessage As String With mDispensaryItem strMessage = "The object properties are: " & vbCrLf _ & "Frame Style " & .FrameStyle & vbCrLf _ & "Frame Size " & .FrameSize & vbCrLf _ & "Quantity " & .Quantity End With MsgBox strMessage, vbOKOnly, "DispensaryItem object contents" End Sub Private Sub mnuFileExit_Click() 'Exit the project Unload Me End Sub Private Sub Form_Unload(Cancel As Integer) 'Release the object reference Set mDispensaryItem = Nothing End Sub