Introduction to Visual Basic 6
Introduction to Visual Basic 6
0
Visual basic is an ideal programming language for developing sophisticated
professional applications for Microsoft windows. It makes use of graphical user interface for
creating robust and powerful applications. Coding in GUI environment is easy and quicker as
compare to traditional, linear programming languages.
Visual Basic was developed from BASIC programming language. It required at least
Microsoft windows 95/NT 3.51, 486 processors and minimum of 16 M.B. of RAM and also
250 MB of hard disk to install complete enterprise edition.
Menu Bar
This is bar display the commands that are required to build an application. The main menu
items have sub menu items that can be chosen when needed.
Tool Bar
The toolbar in the menu bar provide quick access to the commonly used commands.
Toolbox
The toolbox contains a set of controls that are used to place on form at design time thereby
creating the user interface area. Additional controls can be included in the toolbox by using
the Components menu item of the Project menu. A toolbox is represented in fig 1.2
Pointer Picture
Label Textbox
OLE
Fig 1.2
The pointer provides a way to move and resize the control and forms.
Label display a text that the user cannot modify or interact with.
Frame control serves as a visual and functional container for control.
Checkbox display a True/False or yes/no option.
Textbox is a control used to display message and enter text.
The List box display a list of items from which a user can select one.
Combo Box contains a textbox and List box. This allows the user to select an item
from Dropdown List box, or to type in a selection in the textbox.
HScrollBar and VScrollBar controls allow the user to select a value within the
specified range of value.
Timer control executes the timer events at specified intervals of time.
Dirlistbox allows the user to select the directories and paths, which are displayed
Shape control use to draw shape or form.
Image control is used to display icons, bitmaps, metafiles etc
OLE control is used to link or embed an object, display and manipulate data from
other windows based applications.
Picture box displays icons/bmp/jpg and metafiles. It displays text or acts as a visual
container for other controls.
Command Button control which is a part of an option group allows the user to select
only one option even if it display multiple choices.
The FileListBox display a set of files from which user can select the desired one.
The DriveListBox display the valid disk drives and allows the user to select one of
them.
Line control to draw a line on form.
Data control enables the user to connect to an existing database and display
information from it.
Project Explorer
Docked on the right side of the screen, just under the toolbar, is the project Explorer
window. It displays objects of your project like forms, classes and modules. All the object
that make up the application are packed in a project.
Properties Window
The properties window is docked under the project
explorer window. The properties windows expose the various
characteristics of selected objects.
Form Layout
The form layout window uses to place the form starting
position after you runs it.
Scope of variables
A variable is scoped to a procedure-level(local) or module-level depending on how it
is declared. A variable is declared in general declaration section of a Form, and hence is
available to all the procedures. Local variable are recognized only in the procedure in which
they declared. They can be declaring with dim and static keyword.
Local Variable: Local variable is one that is declared inside a procedure. This variable
is only available to the code inside the procedure and can be declared using dim statement as
given below
Dim I as integer
Static Variables
Static variables are not reinitialized each time visual basic invokes a procedure and
thus retains or preserves value even when a procedure ends.
e.g.
Static in as integer
Conversion To Function
Boolean Cbool
Byte Cbyte
Currency Ccur
Date Cdate
Decimals Cdec
Double Cdbl
Integer Cint
Long Clng
Single Cn=sng
String Cstr
Variant Cvar
Error CVErr
Procedure:
Visual basic programs can be broken into smaller logical components called
procedures. Procedures are useful for condensing repeated operations such as the frequently
used calculations, text and controls manipulation etc. The benefits of using procedures in
programming are:
It is easier to debug a program with procedures, which breaks a program into discrete
logical limits.
Procedures used in one program can act as building block for other programs with
slight modification.
A procedure can be sub, function or property procedure
Sub Procedure
A sub procedure can be placed in standard, class and form modules. Each time the
procedure is called, the statement between Sub and End Sub are executed.
Syntax
[private | public ] [ static] Sub Procedure_Name [ (arg_list)]
[Statements]
End Sub
Argument list is separated by commas. Each argument acts like a variable in the
procedure. There are two type of sub procedures namely general procedures and event
procedures.
Event Procedures
An event procedure is procedure block that contains the control’s actual name, an
underscore ( _ ), and the event name
Syntax
Private sub Form1_Load( )
Statement block
End sub
This is event for form1. Execute when load form.
General Procedures
A general procedure is declare when several event procedure perform the same action.
It is good programming practice to write common statements in separate procedure and then
call them in the event procedure
Function Procedures
Function are like sub procedures, except they return a value to calling procedure.
They are especially useful for taking one or more pieces of data, called arguments and
performing some tasks with them. Then function return value that indicate result of the task.
e.g.
The following function procedure calculates area of circle of given radius.
Function Area(a as double) as double
Area = 3.14 * a^2
End Function