What Is an Object-Oriented Programming Language?
First of all, VBA is a pro gramming language. Don’t let this scare you . . .
too much. Hav ing a background in computer science and pro gramming would
be helpful, and you will not be able to take full ad vantage of VBA with out be -
coming (at least) a nov ice pro grammer. How ever, this book guides you through
some of the basic things you might want to do with VBA with out the need of any
pro gram ming background.
To top it off, VBA isn’t just an or dinary pro gramming language; it is an ob -
ject-oriented pro gramming (OOP) lan guage. An OOP lan guage has three key
features: classes, objects, and methods. Classes are types of things, objects are
specific things, and methods are what you do to things. For example, there is a
class of things called “phone books.” The spe cific phone book on my desk is an
object. I can do many things with a phone book, such as look up a person’s phone
number, turn to a page, put it on a chair for my four-year-old daughter to sit on,
etc. All the things that I could do to the phone book are methods. If we convert
this phone book ex ample to computerese (computerese is not a real computer
language, but it plays one on TV), we might have the following:
Dim myPhoneBook As PhoneBook
myPhoneBook.LookUpPerson("John Smith")
The first line says that
myPhoneBook
is a spe cific instance (an ob ject) of
the class
PhoneBook
. This tells us that all the things we can do with phone
books in general can be done to this specific phone book. Since one of the things
that we can do with phone books is look up a specific person, we do that on the
sec ond line.
myPhoneBook.LookUpPerson
says that for this spe cific phone
book, call the method (do the action)
LookUpPerson
. Since we need to know
which per son to look up, this method takes an ar gument (in formation that the
method needs to complete its job). That in formation is put in pa rentheses af ter
the method. Since the in formation is text, we put it in quotes, too.
Computers are very picky. All the de tails are important. The dot (that pe-
riod be tween
Do'stlaringiz bilan baham: |