Вы находитесь на странице: 1из 10

VISUAL BASIC 6.

0
Graphical user interfaces, or GUI’s, have revolutionized the microcomputer industry.
They demonstrate that the proverb, “a picture is worth a thousand words”, hasn’t lost its
truth to most computer users. Instead of the cryptic C :> prompt that DOS user has long
seen (and some have long feared), we are presented with a desk filled with icons and with
programs that use mice and menus.

Perhaps even more important than the look of Microsoft Window applications is the feel
that the applications developed for Windows have. Windows applications generally have
a consistent user interface. This means that users can spend more time mastering the
application and less time worrying about which keystrokes do what within menus and
dialog boxes. Luckily, Microsoft is going to a uniform “look and feel” on all its products,
so users will eventually have to learn a single interface.

While programmer have long had mixed feelings about GUI’s, beginning users like them,
and so/windows programs are expected to be based on the GUI model (and to have the
right look and feel). Therefore, if we need to develop programs for any version of
Windows, we will want a tool to develop GUI-based applications efficiently.

For a long time there were few such tools for developing Windows applications. Before
Visual Basic was introduced in1991, developing Windows applications was much harder
than developing DOS applications.
Programmers had too much to worry about, such as what the mouse was doing, where the
user was inside a menu, and whether he of she was clicking or double clicking at a given
place. Developing a Windows application required expert C programmers and hundreds
of lines of code for the simplest task. Even the experts had trouble.
This is why, when Visual Basic 1.0 was released, Bill Gates, chairman and CEO of
Microsoft, described it as “awesome”. Steve Gibson in InfoWorld said Visual Basic is a
“stunning new miracle” and will “dramatically change the way people feel about and use

69
Microsoft Windows”. Stewart Alsop was quoted in the New York Times as saying
Visual Basic is “the perfect programming environment for the 1990’s”. And as Charles
Petzold, author of one of the standard books on Windows programming is C, put it in the
New York Times: “for those of us who make out living explaining the complexities of
Windows programming to programmers, Visual Basic poses a real threat to our
livelihood”.

The latest version of Visual Basic continues this tradition: sophisticated Windows 95/98
and Windows NT applications can now be developed in a fraction of the time previously
needed. Programming errors don’t happen, as often as they did, and if they do, they’re a
lot easier to detect and fix. Simply put: with Visual Basic, programming for Windows has
become not only more efficient but it has become fun.

Visual Basic 2.0 was faster, more powerful and even easier to use than Visual Basic 1.0.
Visual Basic 3.0 added simple ways to control the most powerful databases available.
Visual Basic 4.0 added support for 32-bit development and began the process of turning
Visual Basic into object oriented programming language. Visual Basic 5.0 added the
ability to create true executables and even the ability to make out own controls. Visual
Basic 6.0 has added long desired language features. Visual Basic 6 offers we more: more
Internet features, better support for database development, more language features to
make our programming jobs easier, more Wizards, more, more, more.

What is Visual Basic 6?

Visual Basic-6 is a development environment that runs under Microsoft Windows. It is


used to write programs that also run under Microsoft Windows. It is the programming
environment used by more programmer than any other in the history (more than 3
million). It combines extraordinary ease of use with great power and flexibility. Visual
Basic is used in many ways and at many levels from novice programmers to the expert’s
artists of programming. Visual Basic language is having several faces. One is Visual,
which comprises of objects and tools that easily assembles themselves into a modern

70
Window interface. Another face is the Visual Basic language, which is an outcome of the
original Basic Language. Basic (Beginners All-Purpose Symbolic instruction Code).
BASIC was invented in the early 1960s. it was intended to be as easy to understand and as
close to layman language as possible. Visual Basic has kept the BASIC tradition intact in
this respect. It is one of the easiest computer languages to work with and understand.

Design-Time vs. Run-Time Environments

Visual Basic is used in two modes; these are design time and run time. In design-time
environment you create and modify objects, design screens (forms) and enter code. The
run-time environment simulates running the program that you created in designing
environment. The run-time simulation has several advantages. One, it makes the
development process faster than it would be if you had to s to compile a program, and
then run it, to determine the impact of the changes you have done in the source program.
Another, the VB run-time environment provides tools that help you understand exactly
what goes on when your applications runs.

Projects & Forms


Starting a New Project

Visual Basic programs are organized into projects. It means that the code written as
procedures (events) will become program when the project is compiled. The forms
contained in the project become windows. Only one project can be opened at a time. Of
course, you can open more than one instance of VB and you can open a project in each
instance. In an instance, you can add more than one project to create a project group. But
in that also only one project can act as the active project. You can start a new project by
using the project dialog displayed when you start the VB.
1. Start Visual Basic
The New Project dialog is displayed (See Fig 1.2)

71
Figure 1.2: Starting New Project
2. Select Standard Exe Project type
3. Press Open

A New Visual Basic project opens (See Figure 1.3)

Figure 1.3: An opened project with default form

72
To disable the initial New Project dialog
1. With the New Project dialog open, put a check mark in the “Don’t show this
dialog in the future” checkbox
2. Click Ok.
The next time when you open Visual Basic, this dialog box will not be there and
Visual Basic automatically starts with a new project loaded

Setting the environment using Option window


1. From the Tools menu, choose Options
The Option dialog opens (See Figure 1.4)

Figure 1.4: Setting the Editor Options


2. On this window go the desired tab whose option you want to set.
For example:
Place a check mark in the “Require Variable Declaration check box” under Editor
tab. It means that you must explicitly enumerate/declare variables your code will
use
Naming Your Project
If you don’t provide any name to your project VB will name it as Project1.
As this name doesn’t tell you much about the project (the project name should be
something meaningful) you might prefer to give it a different name.

73
To name a project
1. From the Project menu, choose Properties (alternatively you can right click on
the project in the project explorer window). The Project Properties dialog open
(See Figure 1.6)

Figure 1.6: Naming Project


2. Type a name for your project in the Project Name Field
3. Type a description of the project in the Project Description field (This is optional)
4. Click Ok
Saving Your Project
You should keep saving your work from time to time to avoid the risk of losing your
work like you do in any other utility program like in Word Processing program.
To save a project
1. From the File menu, choose Save Project or Save Project As The Save File As
dialog opens asking to save the unsaved forms first.
2. Each part of the project like Form is saved in a separate file.
Save each module (part) with a file name and location
3. When all the modules in your project have been saved, you are prompted to
select a file name and allocation for saving your project file.
4. Click Save to save the project file.
Working with VB Forms
As has been earlier, Forms become the windows when a VB project is run; it means
that forms are the basis of the user interface in any program written in Visual Basic.

74
When you open a new VB project, one form comes with it by default. You can add
more forms in your project easily
To add a form to a project
1. Open the Project explorer (if not already open) by choosing Project Explorer
from the view menu or by pressing Ctrl+R or by clicking Project Explorer
button on the Standard toolbar. The Project Explorer displays
all the modules in a project. (See Figure 1.7)

Figure 1.7: Project Explorer


2. Choose Add from the pop-up menu
3. Choose Form. The Add Form dialog appears (See Figure 1.8)

Figure 1.8: Adding a Form to the Project


4. Choose the New tab and then choose Form
5. Click Open
A new form is added to your project now.

75
Some Important Properties of Form
Open Property window (if not open) for the form by choosing the Properties window
option in view menu or by pressing F4 or by clicking on the Properties Window button on
the Standard toolbar. Property window displays the list of all the properties of the control,
which is in focus.
1. Backcolor property: This property is used to change the background color of the
form.
2. Caption property: This property is used to change the Form title.
3. StartupPosition property: This property is used to set the position of the form
when it gets displayed on the screen. There 4 options for this property
0-Manual
1-Center Owner
2-Center Screen
3-Windows default
4. Window State property: This property determines the state of the form when
displayed. The 3 option of this property are
0-Normal
1-Minimised
2-Maximised
5. Font property: This property is used to change the font of the form.

Categorizing Properties
It’s very easy and convenient to work with property list displayed alphabetically
sorted but sometime you may need to set some specific kind of properties. For that you
can
group the properties according to their categories by clicking on Categorized tab on
Properties window. (See Figure 1.9)

76
Figure 1.9: From Property Page
Running a Project
Without having to first compile your project your project you can directly run it as VB
provides a runtime environment in which you can get a feel how the project functions and
thus you can make all the required modifications in it before actually compiling it.

To run a Project
1. If the project has more than one module, you have to select a Startup Object in the
General tab of the Project Properties dialog (See Figure1.10).
Project properties dialog can be accessed from Project menu or pop-up menu, which
appears, by right clicking on the project in Project Explorer window.

77
Figure 1.10 From Project Property
Now do any one of the following:
Click right arrow button on the Standard toolbar
I) Press F5
II) Choose Run from the Run menu.
III) Click yes to save the changes
Now you can see the form in running mode. VB application/forms behave exactly like
any other application. When you minimize the form its icon appears on the task bar of the
window.

78

Вам также может понравиться