Speaker notes to accompany classmoduleintro:

Slide #1:

In this series I am introducing class modules in a very basic example.

Slide #2:

I have set up a class module in this example. To do this go to the project menu and select add class module. Steps are shown on the next slide.

Slide #3:

To create a new class module, select Add Class Module under Project. Class Module is selected so click open and a new class module is created. The window for the code is open.

Slide #4:

I have set up three variables to hold OnHand, OnOrder and Cost.

Now I need to set up the property procedures to handle dealing with OnHand. To do procedures are established for both the Get and the Let. The class allows the properties to be set through the let procedure and retrieved though the get procedure.

"The Property Let and Property Get procedures serve as a gateway to assign and retrieve property values to the private members of the class module. When you define the Property Let and Property Get procedures, the name you use becomes the name of the property to the outside world. " from Advanced Programming using Visual Basic 6 by Bradley and Millspaugh.

See the next slide to see how to add a procedure.

Slide #5:

From the class module, I am using Add Procedure. I have named the Procedure First and selected Property and Public. The results are shown.

Note that I used First and so First becomes the name of the property which now has Let and Get procedures. The default type is variant, which should be changed to an appropriate data type. OnHand on the previous slide was changed to integer.

Slide #6:

This is the code inside the class module - a continuation from slide 4.

Slide #7:

This shows the method that was created. Note that it is created by going to Add Procdure and selection Sub and Public as the options. The intNewAmt as Integer was added inside the parenthesis. This amount, intNewAmt is passed to the ReceiveItem method when it is executed. It is used to increase the module variable modvarOnHand and decrease the module variable modvarOnOrder.

Slide #8:

From the form, I have a button to click when inventory is received. This routine defines intNewAmt and takes in the number of items received and stores it in intNewAmt. It then calls the object method ReceiveItem.

Note that mItem is an object, an instantiation of the CItem class. It is instanciated because of the word New.

Note this also shows the form load where I put actual numbers into the text boxes and then assign these to mItem.OnHand, mItem.OnOrder and mItem.Cost.

Slide #9:

This shows all of the code associated with frmItem including the release of the object reference.

Slide #10:

This shows running PrItemClass.vbp. Note that when Receive Into Inventory is clicked the InputBox shown comes up.

Slide #11:

This is the second program in the series. Here I am changing the cost. Note that I defined cost as an integer.

Slide #12:

This contrasts two approaches used to instanciate the new object. The background is the second program. The overlay is the program shown previously in this slide show. The new approach uses the Set statement when we are ready to actually create the object. Note that we also omit the New keyword when we dimension the object. "A set statement is an assignment statement for object variables. The variable must already be declared (with a Dim, Public, Private or Static statement)." from Advanced Programming with Visual Basic 6 by Bradley and Millspaugh

Slide #13:

This shows the change of price associated with the ChangeCost being clicked.

Slide #14:

First part of the code in the class with PrItemClassEvent.vbp.

Slide #15:

The rest of the code for the class module showing additional uses of RaiseEvent.

Slide #16:

Note that WithEvents must be used when we code Private mItems as CItemSet since this program is going to raise events.

Slide #17:

This shows the event that is executed when the amount on hand falls below 50.

The triggering of the events is shown on the next two slides.

Slide #18:

This shows selling enough to put on hand below 50 which triggers the event that displays the message saying that quantity is below the reorder point of 50.

Slide #19:

This shows receiving 250 into inventory which results in 0 in on order which triggers the event that says there is nothing on order.