Word Document Properties


Chapter 8: Object-Oriented Programming



Download 8,82 Mb.
Pdf ko'rish
bet171/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   167   168   169   170   171   172   173   174   ...   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 201


situations where the message box won’t have three buttons. When the mes-
sage box lacks the proper number of buttons, the code produces an error.
The 
Case Button_4
error-handling logic demonstrates a situation where
you can turn something very complicated into something very simple. None
of the button options has more than three buttons. Therefore, the only time
you can set the default button to the fourth button is when there’s a Help
button. The code looks for this button. When you don’t include it, the code
generates an error.
Using the With Statement
VBA does provide an interesting feature that makes it easier to write code for
an object. The 
With
statement tells VBA that you plan to perform a number
of tasks by using the same object. Every dotted statement within the struc-
ture applies to that object. Using this technique reduces the amount of code
that you have to type and can reduce the chance of typos. Listing 8-8 shows
an example of the 
With
statement in use.
Listing 8-8
Using an Alternative Object-Testing Technique
Private Sub btnTest2_Click()
‘ Instantiate the special message box.
If MsgObj Is Nothing Then
Set MsgObj = New SpecialMsg
End If
‘ Assign some property values.
With MsgObj
.Caption = “This is a message object.”
.Title = “Special Message”
.Buttons = YesNoCancel
.Icon = Question
‘ Display the message box.
.Show
End With
End Sub
Notice that this code is similar to the code in the earlier “Using Your New
Object in an Application” section. The only difference is that you don’t have
to type 
MsgObj
so many times. The code works precisely the same as before,
and you get the same prompts as before. This is a personal-taste coding tech-
nique. You don’t lose anything by not using it, and you don’t gain anything
significant when you do.
202

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   167   168   169   170   171   172   173   174   ...   207




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©www.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