P1: IML
Owen WL040/Bidgolio-Vol I WL040-Sample.cls June 20, 2003 17:37 Char Count= 0
612 VISUALBASICMenu Bar
The Menu bar control is common to most Windows pro-
grams. A menu of related commands drops down when
an item on the Menu bar is clicked. These commands are
also invoked by clicking. Some menu items initiate an ac-
tion immediately, whereas others open additional menus
or dialog boxes.Toolbar
The Toolbar control is also common in Windows pro-
grams. It provides icon-based access to the items in the
menus. In addition to the Standard Toolbar, Visual Basic
provides several specialized Tool bars for specific tasks
such as drawing. Click View on the Menu bar to see a
complete list of the available toolbars.Project Explorer
The complete Visual Basic program is called a Project.
The Project Explorer window uses a hierarchical format
to list all forms, procedure modules, and objects in the
program. The Project Explorer allows the programmer to
instantly access any part of the project by clicking on an
item in the hierarchical list.Properties Window
All objects have sets of properties that define how the
objects will appear and behave. Some properties can be
assigned values when a program is created, whereas oth-
ers are assigned values by the computer system while
the program executes. All properties that can be set by
the programmer are listed in the Properties window. Each
property is listed in the left column, with its current value
displayed in the column to its right. These values can be
changed by clicking the value in the right column and
entering a new value in its place. Property values can
also be changed during program execution by including
appropriate programming statements. See Creating a
Program in the Visual Basic Integrated Development En-
vironmentlater in this document for specific examples
of setting property values. Initially setting the Caption
property to nothing illustrates how to change a property
value in the Properties window. The Visual Basic state-
mentLabel1.Caption = “Hello!”is an example of changing
a property value with programming statements.Form Layout Window
The Form Layout window shows the relative position of
the form on the screen during program execution.Immediate Window
The Immediate window, sometimes called the Debug
window, is not present when Visual Basic is first started.
The Immediate window appears at the bottom of the
screen below the Code and the Form Layout windows.
When the program executes from within the develop-
ment environment the Immediate window displays expla-
nations of errors encountered. The information displayed
in the Immediate window, when used in conjunction with
the other debugging tools available in Visual Basic, re-
duces development time by speeding error identification
and correction.Creating a Program in the Visual Basic
Integrated Development Environment
The following example will help illustrate the various
components of Visual Basic’s IDE. The task for this exam-
ple is to display a simple greeting when the user clicks a
button. Start Visual Basic and select Standard EXE from
the New Project dialog box. Begin creating the user in-
terface by placing a Command Button on the form. This
Command Button, when clicked, will cause the greeting
to appear on the screen. Click the Command Button icon
on the Toolbox, move to the lower center of the Form
Layout Window, and drag open a rectangular box. The
Command Button will appear when the mouse button is
released. With the Command Button still selected, click
Caption in the Properties Window. Change the value in
the right column to “Greet.” This will cause the text on
the button to be changed to “Greet.”
Next place a label on the form to display the greet-
ing. Select the Label icon on the Toolbox and drag open
a rectangular box in the upper center of the Form Layout
Window. The Label will appear when the mouse button is
released. Change the value in the Caption property of the
label to display nothing by erasing all characters in the
right column. The form should resemble Figure 2.
The interface is now complete. The controls, which are
objects, have inherited the operating characteristics and
appearance of similar Windows controls. Test the inter-
face by running the program. Click the Run symbol, the
right-pointing arrow in the Toolbar just below the Dia-
gram menu in the Menu Bar. The Visual Basic Develop-
ment Environment will run the program. Try clicking the
“Greet” button. It will act like a normal Windows but-
ton, but the greeting will not display when the button
is clicked. Clicking is an event that a user can perform
on the “Greet” command button. To display the greeting,
code must be entered into the event-handling procedure
to control what happens when the button is clicked.
Stop the program by clicking the Stop symbol in the
Tool Bar. It is the icon just below the Add-Ins menu in
the Menu Bar. Double click the “Greet” button on the
form. The view will shift from the Form Layout Window
to the Code Window. Visual Basic automatically enters the
header and footer needed to designate this as the proce-
dure that defines what happens when the “Greet” button is
clicked. Between the procedure header,Private Sub Com-
mand1Click(), and the procedure footer,End Sub, enter
the textLabel1.Caption=”Hello”.Private Sub Command1_Click()Label1.Caption="Hello!"End SubThis command will change the Caption property of the
Label control named Label1 to “Hello!” Run the program
again (click the Run symbol) and click the Greet Button.
The label will change from blank to “Hello!.” Stop the
program (click the Stop symbol). Save the program by
selecting the Save option from the File menu on the Menu
Bar. Following the instructions in the subsequent dialog
boxes to complete the save operation.