Vous êtes sur la page 1sur 8

INTRODUCTION TO VISUAL BASIC PROGRAMMING

Visual Basic is a powerful application development tool. It is an object-oriented programming


development system for creating applications that run under any of Microsfts Windows
environment.

What is Visual Basic 6?

The "Visual" part refers to the method used to create the graphical user interface (GUI).
Rather than writing numerous lines of code to describe the appearance and location of interface
elements, we can simply add prebuilt objects into place on screen.

The "Basic" part refers to the BASIC (Beginners All-Purpose Symbolic Instruction
Code) language, a language used by more programmers than any other language in the history of
computing. Visual Basic has evolved from the original BASIC language and now contains
several hundred statements, functions, and keywords, many of which relate directly to the
Windows GUI.

FEATURES OF VISUAL BASIC

* Data access features allow you to create databases, front-end applications, and scalable server-
side components for most popular database formats, including Microsoft SQL Server and other
enterprise-level databases.

* ActiveX technologies allow you to use the functionality provided by other applications, such as
Microsoft Word processor, Microsoft Excel spreadsheet, and other Windows applications. You
can even automate applications and objects created using the Professional or Enterprise editions
of Visual Basic.

* Internet capabilities make it easy to provide access to documents and applications across the
Internet or intranet from within your application, or to create Internet server applications.

* Your finished application is a true .exe file that uses a Visual Basic Virtual Machine that you
can freely distribute.

*Microsoft has introduced a new feature called IntelliSense which enables the system to interact
with other user during coding. The five IntelliSense features are:
• Quick Info- Displays the syntax of the procedure being typed, in a Tool Tip like
window. It also specifies that parameter in bold letters which is being coded at
that instant.
• Complete Word- Automatically completes the word being typed, only after
enough characters have been typed to make the word distinct.
• Data Tips- Displays the value of variable in a yellow tool tip format at run time.
• List Members- Show the list of all properties or methods pertaining to the given
object.
• List Constants- Lists all the constant values for a given object.

The most important types of applications that can be created in Visual Basic are as follows:

1) Standard EXE
It is a typical application and is used to create a standard executable files.

2) ActiveX EXE, Active DLL

ActiveX Components are code – building components which do not have a visible
interface.

3) ActiveX Control
The user can use this type of project to create own custom controls.

4) VB Application Wizard, VB Wizard Manager

The VB Application Wizard help to generate a new fully functional application for the
naïve user.

5) Data Project
It automatically adds controls used for accessing databases to the Toolbox. It also
includes Data Report and Data Environment to generate reports and manipulate databases
respectively.

6) IIS Application, DHTML Application


These are used to create Internet Applications for both Server-side and Client-Side.

7) Addin
Add-ins are special type of commands that can be added to Visual Basic menus, through
the Add-Ins menu.

The VB IDE(Integrated Development Environment)


IDE is a term commonly used in the programming world to describe the interface and
environment that we use to create our applications. It is called integrated because we can access
virtually all of the development tools that we need from one screen called an interface. The IDE
is also commonly referred to as the design environment, or the program.

The working environment in VB is often referred to as the Integrated Development environment


or IDE, because it integrates many different functions such as design, editing, compiling and
debugging within a common environment.

The Visual Basic IDE is made up of a number of components

• Menu Bar
• Tool Bar
• Project Explorer
• Properties window
• Form Layout Window
• Toolbox
• Form Designer
• Object Browser
Title Bar

It displays the name project , Application name and status of the project etc. By default
Project- Microsoft [design].

Menu Bar

The Menu Bar displays 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 toolbars in the menu bar provide quick access to the commonly used commands and
a button in the toolbar is clicked once to carry out the action represented by it.

Toolbox

The Toolbox contains a set of controls that are used to place on a Form at design time thereby
creating the user interface area. Additional controls can be included in the toolbox by using the
Components menu item on the Project menu.

Toolbox window with its controls available commonly.

Control Description
Pointer Provides a way to move and resize the controls form
Displays icons/bitmaps and metafiles. It displays text or acts as a
PictureBox
visual container for other controls.
TextBox Used to display message and enter text.
Frame Serves as a visual and functional container for controls
CommandButton Used to carry out the specified action when the user chooses it.
CheckBox Displays a True/False or Yes/No option.
OptionButton control which is a part of an option group allows the
OptionButton
user to select only one option even it displays mulitiple choices.
ListBox Displays a list of items from which a user can select one.
Contains a TextBox and a ListBox. This allows the user to select an
ComboBox ietm from the dropdown ListBox, or to type in a selection in the
TextBox.
HScrollBar and These controls allow the user to select a value within the specified
VScrollBar range of values
Timer Executes the timer events at specified intervals of time
Displays the valid disk drives and allows the user to select one of
DriveListBox
them.
Allows the user to select the directories and paths, which are
DirListBox
displayed.
FileListBox Displays a set of files from which a user can select the desired one.
Shape Used to add shape (rectangle, square or circle) to a Form
Line Used to draw straight line to the Form
used to display images such as icons, bitmaps and metafiles. But less
Image
capability than the PictureBox
Enables the use to connect to an existing database and display
Data
information from it.
Used to link or embed an object, display and manipulate data from
OLE
other windows based applications.
Label Displays a text that the user cannot modify or interact with.

Project Window (Explorer)

Docked on the right side of the screen, just under the tool bar, is the Project Explorer window.
The Project Explorer as shown in figure servers as a quick reference to the various elements of a
project namely form, classes and modules. The entire object that makes up the application is
packed in a project. A simple project will typically contain one form, which is a window that is
designed as part of a program's interface. It is possible to develop any number of forms for use in
a program, although a program may consist of a single form. In addition to forms, the Project
Explorer window also lists code modules and classes.
The buttons in the tool bar as follows

1. View Code - Displays a window for writing Visual Basic code.


2. View Object - Displays the form to be designed.
3. Toggle folders - This button alternating hides/ shows the Forms folder

Properties Window

The Properties Window is docked under the Project Explorer window. The Properties Window
exposes the various characteristics of selected objects. Each and every form in an application is
considered an object. Now, each object in Visual Basic has characteristics such as color and size.
Other characteristics affect not just the appearance of the object but the way it behaves too. All
these characteristics of an object are called its properties. Thus, a form has properties and any
controls placed on it will have properties too. All of these properties are displayed in the
Properties Window.

Form Designer widow

The form designer window allows the user to ad controls, graphics and pictures to a Form As
needed.

Form Layout window

The Form Layout Window specifies the position of the form on the screen during run
time.

Immediate Window

The Immediate Window at the bottom of the IDE is a debugging tool. When the
application is running, the user can pause it and use the immediate window to check or change
the values of variables in the application.

A project is a collection of files required to build an application. A Visual Basic Project contains
the following files:

1. Form Files
Each form file (.frm) includes a description of the objects and controls on the from and
the related code.

2. Binary Files

For each form file, there exists a binary data file (.frx) containing data of the controls on
the form. The .frx files cannot be edited and are automatically generated for a form file
containing binary properties such as pictures or icons.

3. Standard Modules

These modules contain module level declarations, procedures etc. and are savedas .bas
files.
4. Class Modules

Class modules are templates from which objects are created at run time. They
have the .cls extension.

5. Project File

Visual Basic stores the entire project information in a project file with .vbp extension.

6. ActiveX control file

The ActiveX control file (.ocx) is part of the project, only when optional controls
are added to the project.

7. Resource File

The resource file with .res extension, consist of bitmaps, text strings used in the
application.

Event Driven Programming

Visual Basic programs are built around events. Events are various things that
can happenin a program. this will become clearer when studied in contrast to
proceduralprogramming. In procedural languages, an application is written is executed
by checkingf o r t h e p r o g r a m l o g i c a l l y t h r o u g h t h e p r o g r a m s t a t e m e n t s ,
o n e a f t e r a n o t h e r . F o r a temporary phase, the control may be transferred to some
other point in a program. Whilei n a n e v e n t d r i v e n a p p l i c a t i o n , t h e
p r o g r a m s t a t e m e n t s a r e e x e c u t e d o n l y w h e n a particular event calls a
specific part of the code that is assigned to the event.Let us consider a TextBox
control and a few of its associated events to understand theconcept of event
driven programming. The TextBox control supports various events sucha s C h a n g e ,
Click, MouseMove and many more that will be listed in the
P r o p e r t i e s dropdown list in the code window for the TextBox control. We will
look into a few of them as given below.

The code entered in the Change event fires when there is a change in the contentsof the
TextBox

The Click event fires when the TextBox control is clicked.

The MouseMove event fires when the mouse is moved over the TextBoxAs explained
above, several events are associated with different controls and forms, someof the events
being common to most of them and few being specific to each control

Properties, Methods and Events

All the controls in the ToolBox except the Pointer are objects in Visual
Basic. Theseobjects have associated properties, methods and events.Real world
objects are loaded with properties. For example, a flower is loaded
certaincolor, shape and fragrance. Similarly programming objects are loaded with
properties. Aproperty is a named attribute of a programming object. Properties
define thecharacteristics of an object such as Size, Color etc. or sometimes the
way in which itbehaves. For example, a TextBox accepts properties such as
Enabled, Font, MultiLine,Text, Visible, Width, etc.

Enables property allows the TextBox to be enabled or disabled at run
t i m e depending on the condition set to True or False.

Font property sets a particular font in the TextBox.

MultiLine property allows the TextBox to accept and display multiple lines at runtime.8


Text property of the TextBox control sets a particular text in the control.

Visible property is used to hide the object at run time.

Width property sets the TextBox to the desired width at design time.The properties that
are discussed above are design-time properties that can be set at thedesign tme
by selecting the Properties Window. But certain properties cannot be set
atdesgn time. For example, the CurrentX and CurrentY properties of a Form cannot be
setat the design time.A method is an action that can be performed on objects. For
example, a cat is an object.Its properties might include long white hair, blue eyes, 3
pounds weight etc. A completedefinition of cat must only encompass on its looks,
but should also include a completeitemization of its activities. Therefore, a cat's
methods might be move, jump, play, breathetc.Siimilarly in object-orinted programming,
a method is a connected or built-in procedure,a b l o c k o f c o d e t h a t c a n b e
i n v o k e d t o i m p a r t s o m e a c t i o n o n a p a r t i c u l a r o b j e c t . A method requires
an object to provide them with a context. For example, the word Movehas no
meaning in Visual Basic, but the statement,Text1.Move 700, 400performs a very
precise action. The TextBox control has other associated methods suchas
Refresh, SetFocus, etc.

The Refresh method enforces a complete repaint of the control or a Form.
For example, Text1.Refresh refreshes the TextBox.

The Setfocus method moves the focus on the control. For ExampleText1.SetFocus
sets the focus to TextBox control Text1.

Vous aimerez peut-être aussi