Word Document Properties


Chapter 6: Trapping Errors and Squashing Bugs



Download 8,82 Mb.
Pdf ko'rish
bet129/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   125   126   127   128   129   130   131   132   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Chapter 6: Trapping Errors and Squashing Bugs
11_046500 ch06.qxp 12/5/06 5:35 PM Page 145


The 
If...Then
statement performs a special task. This is one method for
performing a range check — something that you should do for every instance
of input that you receive from a user. The check ensures that the input is
within a specific range. If the input isn’t within the specified range, the code
uses the 
Err.Raise
function to generate an error. User-defined errors fall
within a specific range, so you should always add your custom error number
to 
vbObjectError
to ensure that the number is within the proper range. All
error numbers must be less than 65,535.
Whenever you define a 
custom error
(one that you define), you should tell
yourself exactly where the error occurred. I always include the filename, the
module name, and the 
Function
or 
Sub
name. Notice that the description
information for this error is complete and descriptive. Just because Microsoft
provides ambiguous information doesn’t mean that you have to follow its bad
example. Always include descriptive error messages so that you have a good
idea of what went wrong.
The error handler begins at the 
MyHandler
label. The handler shows the var-
ious 
Err
object properties that you can access to determine the source and
cause of an error. The example could easily include a retry feature, but I
chose to keep things simple. See the earlier “Recovering from an error” sec-
tion for details on a retry feature.
The last statement might not look like much, but it’s very important. Always
clear errors after you handle them, by using the 
Err.Clear
method. If you
don’t, VBA might think that the error is still a problem and fail again.
Reporting errors
It’s essential to report program errors. You can’t overcome problems with
your program when you don’t know about them. In addition, knowing about
errors makes it possible to create a recovery plan. Here are some techniques
that you can use to report errors:

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   125   126   127   128   129   130   131   132   ...   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