Computer
Programming
2
Introduction to Visual Basic
Introduction
• Visual Basic (VB) is a high level programming
language evolved from the earlier DOS version called
BASIC.
• Visual Basic is a software development system
developed by Microsoft to support creating
applications for the Windows operating systems.
• Visual Basic introduced the concept of an event-
driven programming model.
• Visual Basic has incorporated the concept of objects.
History of Visual Basic
• BASIC stands for Beginner’s All-purpose Symbolic
Instruction Code.
• Developed by John Kemeny and Thomas Kurtz in mid-
1960s.
• Visual Basic was developed in mid-1991 by the
Microsoft Corporation.
Why Visual Basic?
• Power and complete Windows application development
system
• Supported by third party products
• Supports the principle of object driven design
• Very flexible
• User- friendly
• Provides a Graphical User Interface or GUI.
• The sequence of instructions executed in the program is
controlled by events
Graphical User Interface (GUI)
• Windows is a Graphical User Interface (or GUI)
GUIs allow users to easily operate computers using a pointing
device (such as a mouse).
• Prior to Windows 3.1 IBM PCs used a command line
interface (MS_DOS)
All commands, input and screen output was textual, one line at a
time.
Without knowing commands users would be unable to proceed.
Event-Driven Programming
• Procedural programs
Execution starts with the first line.
Program moves to different sections as required.
The program calls the OS to get user input.
• Event driven programs
Instead of one program there are independent sets of instruction.
Each (user driven) event is associated with a separate set of
instructions.
Code remains idle until called upon to respond to some event
(button pressing, menu selection,…).
VB Terminologies
• Control
A tool used to create objects on a Visual Basic form. It is used to
create user interface elements, such as command buttons, image
boxes, and list boxes.
• Objects
The name of a user interface element you create on a Visual Basic
form by using a toolbox control. They have what is known as
inherent functionality.
• Property
A value or characteristic held by Visual Basic object, such as
Caption or ForeColor. Properties can be set at design time by using
the Properties window or at run time by using statements in the
VB Terminologies
• Event Procedure
A block of code that is executed when an object is manipulated in
a program. They typically evaluate and set properties and use
other program statements to perform the work of the program.
• Program Statement
A keyword in the code that does the work of the program. They
create storage space for data, open files, perform calculations, and
do several other important tasks.
• Method
A special statement that performs an action or a service for a
particular object in a program.
VB Terminologies
• Class
An implementation of an object type. It has a data structure and
methods that specify the operations that may be used with that
data structure.
• Inheritance
Objects are organized into object classes, which are groups of
objects sharing structural and behavioral characteristics.
• Encapsulation
The result (or act) of hiding the implementation details
(information hiding) of an object from its user.
Integrated Development Environment (IDE)
• Like any other Windows application, VB consists of multiple
windows which appear at startup. The windows that are
displayed when you start VB are collectively known as the
Visual Basic Integrated Development Environment (IDE).
• In particular, VB has the following windows:
Main Window which contains Menu and Toolbar
Toolbox
Project Explorer Window
Property Window
Forms
Code Window
Integrated Development Environment (IDE)
• Like any other Windows application, VB consists of multiple
windows which appear at startup. The windows that are
displayed when you start VB are collectively known as the
Visual Basic Integrated Development Environment (IDE).
• In particular, VB has the following windows:
Main Window which contains Menu and Toolbar
Toolbox
Project Explorer Window
Property Window
Forms
Code Window
Integrated Development Environment (IDE)
• Main Window
This is the only element of the IDE which is always visible. You use
it to select which other IDE elements to view and to add forms or
controls to your project. There are many other features which we
will discuss later.
• Toolbox Window
The toolbox is simply a library of controls which you can place on
your application. It is used to add art work, labels, buttons, list
boxes, scroll bars, menus, and geometric shapes to a user
interface. Once you’ve placed all the controls you need onto your
applications forms, you can hide the toolbox to make room for
working in the other elements of the IDE.
Integrated Development Environment (IDE)
• Project Window
This is simply a list of all forms and modules which make up your
VB project.
• Property Window
Controls such as buttons, scrolling text boxes, pictures boxes and
other features of most VB applications allow you to enter
parameters which define how these controls work. In VB, these
parameters are called properties. Some properties can be entered
at design time within the IDE, while others must be entered with
code while the program is running.
Integrated Development Environment (IDE)
• Form Window
They are the windows which hold the various controls (buttons,
text boxes, etc.) which make up your Application.
• Code Window
This is where you type in the code that VB executes. Notice that
the heading of the window indicates with which event the code is
associated.
Program Development Cycle
1. Analyze: Define the problem
• A common programming error is to begin coding before analysis of
the problem and design of the solution is incomplete.
What is the problem?
Are there any special requirements of the solution?
2. Design: Plan the solution to the problem
• The solution should consist of a logical sequence of steps, called an
algorithm.
Time spent on design should result in a significantly reduced
implementation time.
Program Development Cycle
3. Choose the Interface: Select the objects
4. Code: Translate the algorithm into a programming
language
5. Debug and Test: Locate and remove any errors in the
program
6. Complete the Documentation: Organize all the
materials that describe the program.
Steps in Designing a VB Application
1. Decide on the Interface for the user. (Forms &
Controls)
2. Determine which events the objects on the window
should recognize.
3. Write the events procedures for those events.