Word Document Properties


Chapter 6: Trapping Errors and Squashing Bugs



Download 8,82 Mb.
Pdf ko'rish
bet133/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   129   130   131   132   133   134   135   136   ...   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 149


in Figure 6-4. (See the upcoming “Using the Locals Window” and “Using the
Watches Window” sections for other techniques.) To see this view, simply
hover the mouse over any variable, even an object.
Using the Immediate window
to your advantage
The Immediate window is a valuable debugging tool. You can display the
Immediate window by clicking the Immediate Window button on the Debug
toolbar (refer to Figure 6-3). In Chapter 1, I show how you can actually create
a mini-program by using the Immediate window. It can perform simple assign-
ments, and you can use it to determine the value of a variable.
The Immediate window can act as an output screen. The most common way
to use the Immediate window as an output is the 
Debug.Print
method.
Here in Listing 6-3 is some code showing how to use this valuable debugging
method. (You can find the source code for this example on the Dummies.com
site at 
http://www.dummies.com/go/vbafd5e
.)
Listing 6-3
Using the Debug Object
Public Sub UseDebug()
‘ The variable that receives the input.
Dim InNumber As Byte
‘ Ask the user for some input.
InNumber = InputBox(“Type a number between 1 and “ + _
“10.”, “Numeric Input”, “1”)
‘ Print the value of InNumber to the Immediate window.
Debug.Print “InNumber = “ + CStr(InNumber)
‘ Stop program execution if InNumber is not in the
‘ correct range.
Figure 6-4:
Rely on 
data tips
whenever
possible to
see the
value of a
variable.
150
Part II: Learning the Ropes 
11_046500 ch06.qxp 12/5/06 5:35 PM Page 150


Debug.Assert (InNumber >= 1) And (InNumber <= 10)
‘ Display the result.
MsgBox “The Number You Typed: “ + CStr(InNumber), _
vbOKOnly Or vbInformation, _
“Successful Input”
End Sub
Notice how this sample uses the 
Debug.Print
and the 
Debug.Assert
methods in combination. The 
Debug.Print
method outputs the current
values to the Immediate window, and the 
Debug.Assert
method checks for
a specific input range. When the range is incorrect, the program breaks, and
you can see the errant value in the Immediate window.
Using the Locals Window
The Locals window shows all the variables that the current code segment can
see. You can see variables defined within the current 
Sub
or 
Function
as
well as global variables. You display the Locals window by clicking the Locals
Window button on the toolbar. Figure 6-5 shows a typical example of the
Locals window.
The Locals window displays three kinds of information: variable name, value,
and data type. You can see two global variables at the top of Figure 6-5.
Immediately below the global variables is 
FreeSpace
, a local 
Double
. The
current value is the amount of space on the C drive of my system.

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   129   130   131   132   133   134   135   136   ...   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