introduction to class modules please use speaker notes for additional information!

19
Introduction to Class Modules Please use speaker notes for additional information!

Upload: vivian-black

Post on 24-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Class Modules Please use speaker notes for additional information!

Introduction to Class Modules

Please use speaker notes for additional information!

Page 2: Introduction to Class Modules Please use speaker notes for additional information!

PrItemClass.vbpPrItemClass.vbp

Page 3: Introduction to Class Modules Please use speaker notes for additional information!
Page 4: Introduction to Class Modules Please use speaker notes for additional information!

PrItemClass.vbpPrItemClass.vbp

Page 5: Introduction to Class Modules Please use speaker notes for additional information!

PrItemClass.vbpPrItemClass.vbp

Page 6: Introduction to Class Modules Please use speaker notes for additional information!

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

Page 7: Introduction to Class Modules Please use speaker notes for additional information!
Page 8: Introduction to Class Modules Please use speaker notes for additional information!

PrItemClass.vbpPrItemClass.vbp

Page 9: Introduction to Class Modules Please use speaker notes for additional information!

PrItemClass.vbpPrItemClass.vbp

Page 10: Introduction to Class Modules Please use speaker notes for additional information!

PrItemClass.vbpPrItemClass.vbp

500 + 25 = 525

250 - 25 = 225

Page 11: Introduction to Class Modules Please use speaker notes for additional information!

PrItemClassSet.vbpPrItemClassSet.vbp

Page 12: Introduction to Class Modules Please use speaker notes for additional information!

The object mItem is declared and then instantiated with the Set statement.

Page 13: Introduction to Class Modules Please use speaker notes for additional information!

PrItemClassSet.vbpPrItemClassSet.vbp

Page 14: Introduction to Class Modules Please use speaker notes for additional information!

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.

Page 15: Introduction to Class Modules Please use speaker notes for additional information!

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.

Page 16: Introduction to Class Modules Please use speaker notes for additional information!

PrItemClassEvent.vbpPrItemClassEvent.vbpThe object is declared here and instantiated with the Set statement in the load.

Page 17: Introduction to Class Modules Please use speaker notes for additional information!

PrItemClassEvent.vbpPrItemClassEvent.vbp

This is the other event that is raised or triggered when onorder becomes 0.

Page 18: Introduction to Class Modules Please use speaker notes for additional information!

PrItemClassEvent.vbpPrItemClassEvent.vbp

Page 19: Introduction to Class Modules Please use speaker notes for additional information!

PrItemClassEvent.vbpPrItemClassEvent.vbp