introduction to class modules please use speaker notes for additional information!
TRANSCRIPT
Introduction to Class Modules
Please use speaker notes for additional information!
PrItemClass.vbpPrItemClass.vbp
PrItemClass.vbpPrItemClass.vbp
PrItemClass.vbpPrItemClass.vbp
Option ExplicitPrivate modvarOnHand As IntegerPrivate modvarOnOrder As IntegerPrivate modvarCost As Integer'The value of the property OnHand is kept in modvarOnHand'These variables at the module level are the properties of the new class'These three properties are declared as private and can only be accessed by the procedures'that are within the class module'Since I want access from outside the class, I develop property procedures
'To expose the properties to the outside world, I need get and let proceduresPublic Property Get OnHand() As Integer'Retrieve the current onhand value OnHand = modvarOnHandEnd Property
Public Property Let OnHand(ByVal intOnHand As Integer)'Assign the onhand property value modvarOnHand = intOnHandEnd Property
Public Property Get OnOrder() As Integer OnOrder = modvarOnOrderEnd Property
Public Property Let OnOrder(ByVal intOnOrder As Integer) modvarOnOrder = intOnOrderEnd Property
Public Property Get Cost() As Integer Cost = modvarCostEnd Property
Public Property Let Cost(ByVal intCost As Integer) modvarCost = intCostEnd Property
In the Get, I assigned the private variable to the property name defined when I created the property procedure.
In the Let, I assigned the value received by the Let to the private variable.
PrItemClass.vbpPrItemClass.vbp
PrItemClass.vbpPrItemClass.vbp
PrItemClass.vbpPrItemClass.vbp
PrItemClass.vbpPrItemClass.vbp
500 + 25 = 525
250 - 25 = 225
PrItemClassSet.vbpPrItemClassSet.vbp
The object mItem is declared and then instantiated with the Set statement.
PrItemClassSet.vbpPrItemClassSet.vbp
PrItemClassEvent.vbpPrItemClassEvent.vbp
There are two events that will be raised or triggered when appropriate.
If the modvarOnHand drops below 50 it will raise the event NeedToOrder.
If the mdovarOnOrder = 0 it will raise the event NothingOnOrder.
PrItemClassEvent.vbpPrItemClassEvent.vbp
More code showing when events are raised.
This code also shows a new method - SellProdcut which will decrease the on hand for the product.
PrItemClassEvent.vbpPrItemClassEvent.vbpThe object is declared here and instantiated with the Set statement in the load.
PrItemClassEvent.vbpPrItemClassEvent.vbp
This is the other event that is raised or triggered when onorder becomes 0.
PrItemClassEvent.vbpPrItemClassEvent.vbp
PrItemClassEvent.vbpPrItemClassEvent.vbp