Word Document Properties



Download 8,82 Mb.
Pdf ko'rish
bet121/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   117   118   119   120   121   122   123   124   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Figure 6-1:
Balloon help
helps locate
syntax
errors in
your code.
135
Chapter 6: Trapping Errors and Squashing Bugs
11_046500 ch06.qxp 12/5/06 5:35 PM Page 135


to look for errors that prevent the program from running properly. You might
create an 
If...Then
statement and not include the corresponding 
End If
statement. The compiler runs constantly, so VBA finds some mistakes almost
immediately after you make them.
VBA uses the compiler to find many of the syntax errors that you make and
displays an error message. You can try this feature. Open a new project,
create a 
Sub
(the name isn’t important), and type 
MsgBox()
. Then press
Enter. VBA displays a message box stating that it was expecting an equals
sign (=). When you use parentheses after 
MsgBox
, VBA expects that you want
to include a result variable to hold the result, such as 
MyResult =
MsgBox(“My Prompt”)
. You should also notice that the errant line of code
appears in a highlight color, which is normally red.
Missing elements are another syntax error that VBA finds with relative ease.
When you fail to include an 
End If
statement for an 
If...Then
statement,
VBA always finds it and displays an error message. However, VBA doesn’t
find this error in most cases until you try to run the program. In addition, it
doesn’t show the errant 
If...Then
statement — VBA normally highlights
the 
End Sub
or 
End Function
statement instead, thus making this error a
little harder to find.
The compiler also finds many of the punctuation errors that you can make in
your code. When a line of code becomes too long and you try to move to the
next line without adding a continuation character, the compiler notices the
error and tells you about it. (See the “Writing Your First Sub” section of
Chapter 3 for a description of the continuation character.) The compiler also
notes missing periods between elements of a statement or missing parenthe-
ses from function calls (when needed).
When you add 
Option Explicit
to your code, the compiler checks vari-
ables for a number of problems. You could try to assign a string value to an
integer. VBA allows you to make this error when you type the code. However,
when you try to run the code, the compiler sees the type mismatch and tells
you about it. The compiler can detect many variable errors that would go
unnoticed otherwise, thus making your code less likely to contain errors.
Understanding run-time errors
A
run-time error
happens when something outside your program is incorrect.
A disk access request can fail, or you can type the wrong information. Your
VBA code is correct, but the program still fails because of this external error.
Run-time errors are the reason why many large companies, such as Microsoft,
run beta programs. (A 
beta program
is a vendor-sponsored method of getting
a program before its developers have finished it for the purpose of testing
136

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   117   118   119   120   121   122   123   124   ...   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