Word Document Properties


Chapter 8: Object-Oriented Programming



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


Adding Error Handling to Classes
Classes have to provide exceptionally robust error handling so that they’re
reliable. The earlier “Defining methods” section shows one type of error 
handling that you can add to a class. Keeping track of property interactions
before you perform a task such as displaying the message box is important.
You can add other forms of error handling to your class. Tracking actual
input values is another good form of error handling when you can’t use enu-
merated constants. It’s also important to monitor property values based on
other input values. Here’s an example of code (see Listing 8-7) that monitors
the 
DefaultButton
property based on the number of buttons that the mes-
sage box has. The code ensures that the default button is a button that actu-
ally exists on the message box.
Listing 8-7
Providing Error Handling in an Object
Public Static Property Let DefaultButton(Value As
DefaultButtonTypes)
‘ Change the value of the message icon based on the
‘ input value.
Select Case Value
Case Button_1
UseDefault = vbDefaultButton1
Case Button_2
If ((UseButtons = vbOKOnly) And _
(Not UseHelpButton)) Then
‘ Can’t have a single button setting if
there is no Help button, so raise an
‘ error.
Err.Raise vbObjectError + 2, _
“SpecialMsg.DefaultButton”, _
“The selected default button value is “ +
_
“incorrect. Choose a default button “ + _
“that matches the message box settings.”
Else
‘ Set the default button value.
UseDefault = vbDefaultButton2
End If
Case Button_3
If ((UseButtons = vbOKOnly) Or _
(((UseButtons = vbOKCancel) Or _
(UseButtons = vbRetryCancel) Or _
(UseButtons = vbYesNo)) And _
(Not UseHelpButton))) Then
‘ This setting doesn’t support a single
‘ button option at all. It also doesn’t
‘ support any of the double button options
200

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   165   166   167   168   169   170   171   172   ...   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