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


614 VISUALBASIC

values of all variables being watched are displayed in the
Watch window. Variables can be added to the Watch win-
dow before the program is executed, or when a breakpoint
is reached. To add a variable to the Watch list, right click
the variable name in a program statement and select the
Add Watch option. To remove a variable from the Watch
list, select the variable in the Watch window and click the
Debug menu in the Menu bar. Select Edit Watch and click
Delete (Eliason & Malarkey, 1998).
Another very useful Visual Basic debugging tool is the
Data Tips window. While the program is in break mode,
position the cursor over a variable name in the code.
A Data Tips window will display showing the current
contents of the variable. Data Tips windows are used to
check the contents of variables not in the Watch window
(Harriger et al., 1999).
Visual Basic can also step through the program, execut-
ing one instruction at a time. This is called Single Step-
ping. After executing an instruction, the program high-
lights the next instruction and pauses in the same manner
as at a breakpoint. Pressing the F8 key causes the highlight
instruction to execute. The next instruction is highlighted
and execution pauses again. A breakpoint is usually set to
stop program execution at a specified point. The Single
Step feature allows execution of all or part of the remain-
ing instructions one at a time (Harriger et al., 1999).
The debugging tools available in Visual Basic are most
effective when used in combination. Watch windows and
Data Tips windows allow the programmer to see what is
happening “inside” the program as it runs. This informa-
tion can help identify instructions that are not producing
expected results. Single Stepping through a program also
allows the programmer to see exactly which statements
are executing and in what order. This can help identify
problems in modules, loops, and decision structures.

VISUAL BASIC LANGUAGE ELEMENTS
Visual Basic is a high-level programming language with
a rich command set. Its heritage as an instructional lan-
guage makes Visual Basic suitable for a wide range of pro-
gramming tasks. Over the years, vendor refinements and
enhancements have addressed and corrected most of the
problems and shortfalls of the original Dartmouth speci-
fications. Some key elements are discussed below.

Variables
Specific variable declarations are not required in the origi-
nal BASIC language. This option remained in Visual Basic
through Version 6.0 (Evjen & Beres, 2002). Although using
variables that are not specifically declared may speed pro-
gram development somewhat, they are difficult to manage
and often lead to errors. Any variable not specifically de-
clared is created with the Variant data type, which is very
inefficient. Good programming practice dictates that vari-
ables be specifically declared before use. To facilitate this,
Visual Basic through Version 6.0 offered the Option Ex-
plicit statement. The Option Explicit statement is placed
in the General Declarations section of the Visual Basic
program. It disables Visual Basic’s automatic variable dec-
laration option, forcing all variables to be declared in

the program’s code. Automatic variable declaration is not
supported in the latest release of Visual Basic, Visual Basic
.NET (Evjen & Beres, 2002).
Variables are declared using the Dim statement. As
with all programming languages, each variable must have
a unique name. With the release of Visual Basic.NET, all
data types follow the Common Language Specification
(CLS) incorporated into Microsoft’s .NET framework. To
achieve this compliance, some of the data types available
in Visual Basic 6.0 and earlier versions have been elimi-
nated. Other Visual Basic 6.0 and earlier data types have
been changed to fit CLS naming conventions. Below is a
partial list of data types available in Visual Basic. Differ-
ences between Visual Basic 6.0 and Visual Basic.NET are
noted (Evjen & Beres, 2002).

Boolean
The Boolean data type is a 2-byte field that contains True
or False values.

Char
Char is a 2-byte field that contains unsigned integer values
between 0 and 65,535.

Date
Date is an 8-byte field that contains date values between
January 1, 1 and December 31, 9999. The Date type in
Visual Basic 6.0 and earlier versions is replaced by the
Long data type in Visual Basic.NET.

Decimal
Decimal is a 12-byte field that contains real
and integer numbers. The integer range is
±79,228,162,514,264,337,539,950,335. The real number
range is ±7.9228162512265337593543950335 with 28
places to the right of the decimal point. This data type is
called Currency in Visual Basic 6.0 and earlier versions.

Double
Double is an 8-byte field that contains real num-
bers in the range from −1.797693134862231E308 to
1.797693134862231E308.

Integer
Integer is a 4-byte field that contains integer values in
the range±2,147,483,648. The Integer data type in Vi-
sual Basic 6.0 and earlier versions is equivalent to Visual
Basic.NET’s Short data type.

Long
Long is an 8-byte field that contains integer val-
ues in the range −9,223,372,036,854,775,808 to
9,223,372,036,854,775,807. This data type did not
exist in Visual Basic versions prior to Visual Basic.NET.

Short
Short is a 2-byte field that contains integer values between
−32,768 and 32,767. This data type was called Integer in
Visual Basic 6.0 and earlier versions.
Free download pdf