Object-Oriented Programming in VBA: Basic Co Ncepts Cta 9
Object-Oriented Programming in VBA: Basic Co Ncepts Cta 9
in VBA
n ce p t s
Ba s i c co Adapted from Slides
By Prof. Adrian Holzer
9
(JAVA) With kind
CT A permission
Today
Classes
Objects
Goals
• Understand basic Object programming
concepts
• Be familiar with Objects when working with
Excel’s object model (next lesson)
• Improve the structure of your programs if
you’ll be making extensive use of VBA
Objects
(what it does)
(how it does
it)
Specification viewpoint
Methods & Parameters
rotate()
Methods & Parameters
Rotate(degrees as integer)
Methods & Parameters
Rotate(degrees
as integer)
Implementation Viewpoint
(how it does
it)
Instances
class Chair
Color as String
Model as String
IsBroken as Boolean
Age as Integer
Property (Field) Values
An object stores its own values for each property /
field
Chair myChair1
color “green”
model “shell”
isBroken false
age 5
Age as Integer
Sub test()
Dim myEmployee As CEmployee
Creation of a new
object
Using properties
Properties are accessed / modified in the
same way as fields of a user-defined type
myEmployee.name = "Paul"
myEmployee.birthDate = CDate("03.03.1966")
myEmployee.grossSalary = 100000
MsgBox myEmployee.name
method’s signature
Q:
How is that price determined?
Q:How is ‘money’ entered into a machine?
Q:How does a machine keep track of the money that is entered?
Specification
(what it does)
Implementation
(how it does
it)
References
[Seref 07] Michelle M.H. Şeref, Ravindra K. Ahuja, and Wayne L. Winston ;
Developing Spreadsheet-Based Decision Support Systems Using Excel and
VBA for Excel ; Dynamic Ideas, Belmont, Massachusetts 2007
http://msdn.microsoft.com/en-us/library/office/aa164936(v=office.10).aspx