Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
• Visual Basic - The Basic Canvas
Everytime you load a VB or VBA project, you will be
greeted by roughly the layout shown in Figure 1 and
these five GUI tools. First, the toolbox(1) contains all
the GUI elements/controls needed to create any VB
form and the front end to all VB programs.
For example, after the pointer tool there is the image
control, label, textbox, frame and command button as
the first five of 20 standard controls which are used
constantly in VB programs.
Another advanatge of these basic controls is that they fill
60-90% of all your programming needs and are
automatically included in the VB runtime. It is possible
to add many other Micrsoft supplied or third party
components/controls to this toolbox.
• Second is form(2). you can size it, color it,
give it a caption ("Database Test" in this case)
and fill the form with GUI controls which help
your program do useful works. Putting
controls on your form is as easy as clicking on
the control (say the command button) in the
toolbox and then dragging and sizing it on
your form(see the "Exit" button on the form).
• The third part of the Basic canvas are the
menus and toolbars(3) which manage and
control all of VB. Yes indeed there are lots of
commands and operations to learn. Most
students will be familiar with many of the
menu and icons. File, Edit, View, Run,
Window, Help menus should be familiar to
any Word Perfect, Excel, or Netscape users.
Likewise icons for File Open, File Save, Cut,
Copy, Paste, Find, Run programs, Pause
Program, Halt Program can be seen along the
toolbar.
• Fourth is the Project Explorer
(4)which you use to access all the forms
and coding files in your VB program.
The PE-Project Explorer is such a handy
navigation device you will find yourself
using it all the time to switch among
different forms and code.Yes, even in
small to medium-sized programs
multiple forms are easy to do and quite
common.
• Fifth, and even more frequently used than the
Project Explorer is the Properties
sheet(5). Note that the "Exit" command button
is highlighted in the form and is also the control
listed in the Properties sheet. If you want to
change the property of any control like its
color, shape, caption, or whatever - the Property
sheet is the place to go. But a command button
has 32 properties - and some controls have
hundreds. Fortunately, the 80-20 rule applies -
for example, 80 % of operations can be done
with 6 properties on the command button -
Appearance, Caption, Enabled, Tooltip,
TabIndex, and Visible.
• You will find in developing in Visual
Basic that you spend a large percentage
of time using the Project Explorer
and Property sheet. It is worthwhile
to get to know them well. Project
Explorer is your means of navigating
around the various parts of VB; while
Property sheets allows you to set the
very basic look and feel plus behaviour
of all your forms in Visual Basic.
VB Interface
•
• Return to VB Project Explorer
VB's Project Explorer is key navigation aid among all the forms
and code that make up a Visual Basic program.
• If the Project Explorer window is not showing just click the View
| Project Explorer menu items (or Ctrl+R keyboard shortcut) to
pop it up like in Figure on previous slide.
• As you might expect the Project Explorer works very much like
Windows Explorer.
There are two folders - one for all the forms used in a VB
program project and another for all the modules. Modules are
Visual Basic program code that can be called and used anywhere
in the VB program.
By clicking on the forms folder it expands out to show all the forms
used in a VB program project. In effect the project file (.vbp file
extension) keeps track of all the resources used in a VB program.
Project Explorer is a window into that project file.
• To add new forms to a project click on
the Project | Add Form menu item. To
delete a form no longer needed in a
project click on the form in Project
Explorer the select the Project | Remove
menu items. However, the most
common use of the Project Explorer is to
quickly move among forms and
modules.
• As shown in Figure , clicking on
the code icon brings up the text
editor loaded with any code
associated with the highlighted
form or module. Right next to
the code icon, is the form icon -
clicking on this icon brings up
the form ready for visual
programming. Allternately, one
can double or rightmouse click
on the form or module also to
quickly navigate to where you
want to go.
The Visual Basic Text Editor
• The Visual Basic Text Editor
On start up, Visual Basic 6.0 will display the following dialog box as shown in figure
You can choose to start a new project, open an existing project or select a list of recently opened
programs.
There are various types of applications we could create, however, we shall concentrate on creating
Standard EXE programs (EXE means executable program).
Now, click on the Standard EXE icon to go into the actual VB programming environment.
The Visual Basic Environment consists the
following :
Visual Basic Environment
• A Blank Form for you to design your
application's interface.
‘ A Comment!
• Terminate a program.
End
Example 1
List of Procedures Private Sub Form_Load ( )
Form1.show
Do not have to worry about the beginning and the
Print “Welcome VB”
end statements (i.e. Private Sub Form_Load.......End End Sub
Sub.);
Example
Private Sub Form_Activate ( )
x = 20
y = 10
Print x + y
Print x - y
Print x * y
Print x / y
End Sub
Concatenation Example
Private Sub Form_Activate( )
A = "Tom"
B = “likes"
use the + or the & C = “to"
operator to join two or D = “eat"
E = “burger"
more texts (string) Print A + B + C + D + E
together like in End Sub
examples Example
Private Sub Form_Activate()
A = "Tom"
B = “likes"
C = “to"
D = “eat"
E = “burger"
Print A & B & C & D & E
End Sub
Steps in Building a Visual Basic Application