Word Document Properties


Chapter 8: Object-Oriented Programming



Download 8,82 Mb.
Pdf ko'rish
bet154/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   150   151   152   153   154   155   156   157   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Chapter 8: Object-Oriented Programming
14_046500 ch08.qxp 12/5/06 5:36 PM Page 183


To build an object, you tell VBA to 
instantiate
(create an instance of) the
object. All the code required to build the object appears in the class. As a
VBA user, you create the class and not the object. Here’s a simple example of
the two-step process used to instantiate an object:
‘ Create a reference to the file system.
Dim MyFileSystem As FileSystemObject
‘ Create a reference for the target drive.
Dim MyDrive As Drive
‘ Fill these two objects with data so they show the
‘ available space on drive C.
Set MyFileSystem = New FileSystemObject
Set MyDrive = MyFileSystem.GetDrive(“C”)
VBA creates the object, 
MyFileSystem
, based on the blueprint provided by
the 
FileSystemObject
class. Likewise, VBA creates the object, 
MyDrive
,
based on the 
Drive
class.
Telling VBA that you want to create these two objects by using the 
Dim
state-
ment is not the same as instantiating them. The 
Set
statement instantiates
the object. You 
Set
an object equal to the blueprint contained within a class.
You can instantiate objects by using a number of techniques — the previous
example shows two of them. In the first case, 
MyFileSystem
is instantiated
by using the 
New
keyword and the name of the class
FileSystemObject
.
In the second case, 
MyDrive
is instantiated based on an existing object con-
tained within the 
MyFileSystem
object. The 
GetDrive
method tells VBA
which 
Drive
object to use within the 
MyFileSystem
object.
Considering class types
Classes come in two varieties: components and controls. A 
component
is a
class that describes an object without a user interface. The 
FileSystem
Object
class is a component. It shows VBA how to create an object that
lacks a user interface. You usually create components with VBA. All the 
examples in this book (such as the upcoming Listing 8-1) show how
to create components.

control
is a class that describes an object that includes a user interface or
affects the user interface. The 
CommandButton
class is a control because it
includes a user interface. Don’t assume that every control provides a view-
able piece of the user interface. When you use the 
Timer
class, it’s still a 
control (even if it doesn’t have a user interface) because it interacts with the
user and affects the user interface. It’s very hard to create controls with VBA.
You should use another language — such as Visual Basic (not VBA), Visual
184

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   150   151   152   153   154   155   156   157   ...   207




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish