The Internet Encyclopedia (Volume 3)

(coco) #1

P1: IML


Owen WL040/Bidgolio-Vol I WL040-Sample.cls June 20, 2003 17:37 Char Count= 0


THEVISUALBASICUSERINTERFACE 613

Figure 2: Greet Exercise sample form.

Program Development and Debugging
Programming errors happen. Any program of any signif-
icant size or complexity will certainly have at least one
error in it. The process of locating and fixing these errors
is called debugging. Since debugging is such an impor-
tant (and frequent) part of the application development
process, Visual Basic includes special tools to aid in locat-
ing and correcting problems

Error Types
There are three types of programming errors: syntax er-
rors, runtime errors, and logic errors. Syntax is the set of
rules that must be followed when language statements are
written. Syntax errors occur when program statements do
not follow these rules. Misspelling a Visual Basic keyword
is an example of a syntax error.
Runtime errors occur when the computer cannot ex-
ecute a statement. The statement is syntactically correct,
but some aspect of the command prevents it from being
executed. For example, the statementC=A/Bis syntacti-
cally correct. However, if B has a value of zero at runtime,
the statement cannot be executed because division by zero
is not mathematically possible.
The final type of error is the logic error. All statements
in the program are syntactically correct and the program
encounters no runtime errors, but the results are not as
expected. The instructions are perfectly legitimate Visual
Basic, but they do not properly perform the specified

task. An empty label on a form where output was ex-
pected is an example of a logic error (Eliason & Malarkey,
1998).

Visual Basic Debugging Tools
One of the most useful Visual Basic debugging tools is the
breakpoint. A breakpoint is a marker placed in the pro-
gram. The program will temporarily stop running when a
breakpoint is encountered. This allows the programmer
to use other debugging tools to obtain information about
the program while it is paused in midexecution. To set a
breakpoint, first place the cursor on the desired program
statement. Press F9 or click in the gray margin to the left of
the statement. The statement will be highlighted, usually
in red, and a large dot will appear in the grey margin to the
left of the line. At execution, the program pauses before
executing this statement. The Visual Basic environment
is now in Break mode. The statement at which the pro-
gram paused is highlighted and a yellow arrow appears
on the dot in the gray margin. To continue executing the
program, click on the Run symbol in the Standard toolbar.
The program will continue to execute until it reaches an-
other breakpoint or runs to completion. Breakpoints are
removed by clicking the dot in the gray margin to the left
of the statement.
Once the program reaches a breakpoint and pauses,
the programmer can check the values in selected vari-
ables by using the Watch window. Selecting a variable
to be “watched” opens the Watch window. The current
Free download pdf