0% found this document useful (0 votes)
19 views

Unit1 VB

Uploaded by

sahilgenius12345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Unit1 VB

Uploaded by

sahilgenius12345
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

INTRODUCTION

VISUAL BASIC is a high level programming language evolved from the earlier
DOS version called BASIC. BASIC stands for Beginners' All-purpose Symbolic
Instruction Code. The program codes in Visual Basic resemble the English
language. Visual Basic is a fairly easy programming language to learn.

VISUAL BASIC is a VISUAL and events driven Programming Language. V.B is


very powerful programming system that helps one develop sophisticated, graphical
applications that can be run on Microsoft Windows environment.

V.B is actually BASIC (Beginner’s All purpose Symbolic Instruction Code)


language, which is visual in its nature. i.e. it is used to create GUI applications i.e.
visual Programming style involves a lot of illustrations (graphics entities), rather
than writing numerous lines of code to describe the appearance, functioning etc, of
the application’s interface Visual Basic is event-driven because users may click on
a certain object randomly, so each object has to be programmed independently to
be able to response to those actions (events).

Examples of events are clicking a command button, entering text into a text box,
selecting an item in a list box etc. Therefore, a VISUAL BASIC Program is made
up of many subprograms; each with its own program code which can be executed
independently and at the same time can be linked together in one way or another.

NEED OF VISUAL LANGUAGES OR IMPORTANCE OF VB


Visual Basic is regarded as the third generation event-driven programming
language. It was released in 1987. Being the first visual development tool
from Microsoft, it is considered as one of the most powerful programming
languages. As compared to other computer programming languages, such as,
C, C++, it is easy to learn and understand, provided that one has determination
and dedication to do so.
Visual basic programming language allows programmers to create software
interface and codes in an easy to use graphical environment. VB is the
combination of different components that are used on forms having specific
attributes and actions with the help of those components. On the one hand it
allows programmers to develop widows based applications rapidly; on the
other hand, it helps greatly in accessing data bases, using ADO while letting
the programmers use ActiveX controls and various objects. While it is
intended more to develop applications, it is also useful for games development
for particular or limited purposes, unlike C++ that is more suitable for
developing games.

As compared to other languages, Visual basic may be slower though, yet it is


flexible and it can be rightly said that things that are difficult in other
languages are comparatively easier in visual basic programming language. It
may also be said that, since it is one of the most popular programming
languages, lots of related books and material and other resources are available
and can be accessed for developing programming skills at visual basic
programming language conveniently.
One of the most important things to be considered with regard to programming
in Visual basic is that the structure of VB is designed in a way that allows
programmers to create executable code – Exe files. It enables programmers to
develop programs that can be used as front end to databases. Besides, it’s with
the help of visual basic tools, one can change the abstract ideas into programs
or into the whole software while it allows revising and modifying the
programs fittingly.
Once you have advanced your skills at visual basic programming language,
you can move to develop your skills at other languages, such as, VB script.
However, it all depends upon your interest and desire. It must be noted that the
sole objective of any computer programming language is to save time and
efforts of the users while making their lives easier. Visual Basic is one of the
most important programming languages having a powerful front-end tool
which is able to achieve simple and complex business requisites in and
effective and efficient manner.

EVOLUTION OR HISTORY OF VISUAL BASIC

BASIC (Beginners All Purpose Symbolic Instruction Code) was developed in


1960’s by Profs Kemeny & Kurtz. 1970’s Bill gates implemented BASIC in
several PCs’. Alan Cooper is considered the father of Visual Basic. In 1987,
the then Director of Applications Software for Coactive Computing
Corporation wrote a program called Ruby (Tripod) that delivered visual
programming to the average programmer/user. Alan Cooper developed VB and
sold to Microsoft in 1988. The Visual Basic (VB) system is a fourth generation
programming system which produces much of the code itself as the
programmer designs the interface for his or her application. Microsoft surveys
in the late 1990's showed that roughly two-thirds of all business applications
programming on PCs was being done in Visual Basic. Visual Basic 1.0 for
Windows was first released on May 20, 1991 at the Windows World
convention in Atlanta Georgia. VB version 2.0 for Windows (November 1992)
was faster, more powerful and easier to use than version 1. VB 2 was also
available in a freeware student release called the Primer edition. Visual Basic
3.0 (1993) added tools to access and control databases and Object Linking and
Embedding (OLE) version 2. It came in Standard and Professional versions. A
superset of VB, called Visual Basic for Applications, was released as part of
Microsoft Excel 5 and Microsoft Project 4 in 1993. It has since become the
internal programming language of the Microsoft Office family of products, and
is available for license by other software companies. Visual Basic 4 was
released in 1995 and supported the new Windows 95 family of 32-bit operating
systems. The Professional Edition could also compile code to run on the older
16-bit Windows 3.x systems. Visual Basic Scripting Edition (VBScript) was
also announced in 1995. VBScript is used to write embedded code for
inclusion in web pages, although not all web browsers will run VBScript.
Visual Basic 5 added, among other things, the ability to create true executables
and to create your own custom controls. It also supported Microsoft's Active-X
technology. Visual Basic 5 was available in Standard (Learning), Professional
and Enterprise Editions. Visual Basic 6 (VB6) was introduced in 1998 and was
included as part of a package known as Visual Studio 6.0. VB6 added new
capabilities in the areas of data access, Internet features, controls, component
creation, language features and wizards. To quote Microsoft's web site, «Visual
Basic features provide graphical, integrated data access to any ODBC or OLE
DB data source, and additional database-design tools for Oracle and Microsoft
SQL ServerTM-based databases. New Web development features bring the
easy-to-use, component-based programming model of Visual Basic to the
creation of HTML- and Dynamic HTML (DHTML)-based applications. Many
organizations are still using this version today.
Non Visual Programming: ∙
Non Visual Programming does not require IDE: Integrated Development
Environment. ∙
In Non-Visual Programming, there is no IDE, so developer has to be master in
language syntax & fast typing as well for the fast development.
Non Visual Programming does not provide such features.
In Non-Visual Programming, you have to create program textually, no GUI
is there, only Text based interface.
With Non Visual Programming, You have to write down program in the
form of text only.
Non Visual programming is difficult but also increase you memory power
and logic.

PROCEDURAL, OBJECT-ORIENTED AND EVENT DRIVEN


PROGRAMMING LANGUAGES

PROCEDURAL PROGRAMMING:
Procedural Programming can be defined as a programming model which is
derived from structured programming, based upon the concept of calling
procedure. Procedures, also known as routines, subroutines or functions,
simply consist of a series of computational steps to be carried out. During a
program’s execution, any given procedure might be called at any point,
including by other procedures or itself.
Languages used in Procedural Programming: FORTRAN, ALGOL, COBOL,
BASIC, Pascal and C.

PROCEDURAL PROGRAMMING LANGUAGES:


 In procedural programming, program is divided into
small parts called functions. Procedural programming
follows top down approach.
 There is no access specifies in procedural programming.
 Adding new data and function is not easy.
 Procedural programming does not have any proper way
for hiding data so it is less secure. ∙ In procedural
programming, overloading is not possible.
 In procedural programming, function is more important
than data.
 Procedural programming is based on unreal world.
 Examples: C, FORTRAN, Pascal, Basic etc.

OBJECT ORIENTED PROGRAMMING:


Object oriented programming can be defined as a programming model which
is based upon the concept of objects. Objects contain data in the form of
attributes and code in the form of methods. In object oriented programming,
computer programs are designed using the concept of objects that interact
with real world. Object oriented programming languages are various but the
most popular ones are class based, meaning that objects are instances of
classes, which also determine their types. Languages used in Object Oriented
Programming: Java, C++, C#, Python, PHP, JavaScript.

OBJECT ORIENTED PROGRAMMING:


 ∙ In object oriented programming, program is
divided into small parts called objects. ∙ Object
oriented programming follows bottom up
approach.
 ∙ Object oriented programming have access
specifiers like private, public, protected etc. ∙
Adding new data and function is easy.
 ∙ Object oriented programming provides data hiding so it is more
secure.
 ∙ Overloading is possible in object oriented programming.
 ∙ In object oriented programming, data is more important than
function.
 ∙ Object oriented programming is based on real world.
 ∙ Examples: C++, Java, Python, C# etc.

EVENT DRIVEN PROGRAMMING


Event-driven programming is a programming paradigm in which the
flow of program execution is determined by events - for example a user
action such as a mouse click, key press, or a message from the operating
system or another program is known as the Event Driven Programming.
VB programming is also based on Events.
An event-driven application is designed to detect events as they
occur, and then deal with them using an appropriate event-handling
procedure.

When you fire an event, the code in the event procedure is executed,
and then visual basic performs its operations as per the instructions
written in the event procedure code. For example, in the first sample
program, when you click the 'Print' button, the click event is fired,
and then the code in the click event procedure gets executed. The
code tells Visual Basic to print a text on the form. So as a result, you
see a text printed on the form.

Example:
Write the following code in the DblClick event procedure of the form.

Private Sub Form_DblClick()


Print "You have double-clicked" End Sub

OUTPUT
When you double-click on the form, the DblClick event procedure of the Form
object is invoked, and then the code in the DblClick event procedure is
executed. Thus, the code instructs Visual Basic to print a text on the form.
then the code in the DblClick event procedure is executed. Thus, the code
instructs Visual Basic to print a text on the form.

INTEGRATED DEVELOPMENT ENVIROMENT


An Integrated Development Environment (IDE) is a software application that
provides comprehensive facilities to computer programmers for software
development. An IDE normally consists of a source code editor, build
automation tools and a debugger.

WHY VB IS CALLED IDE


One of the most significant changes in Visual Basic 6.0 is the Integrated
Development Environment (IDE). 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.
Integrated Development Environment (IDE) consists of inbuilt compiler,
debugger, editors, and automation tools for easy development of code.
Visual Basic.net 2006 IDE can be accessed by opening a new project. IDE
was first introduced with version 5.0 and Integrated Development
Environment of Visual Studio.net 2008 had undergone minor design changes.
VB IDE consists of Solution Explorer, Toolbox, Form, Properties Window,
and Menu Bar. In Visual Studio windows related to a project are combined
together and placed at certain locations on the screen. This type of IDE is
known as Multiple Document Interface or MDI. It also having the great
feature called as drag and drop. We can drag & the drop the controls without
writing single line of coding. The below diagram shows the development
environment with all the important points labeled. Many of Visual basic
functions work similar to Microsoft word e.g. the Tool Bar and the tool box
is similar to other products on the market which work off a single click then
drag the width of the object required. The Tool Box contains the control you
placed on the form window. All of the controls that appear on the Tool Box
controls on the above picture never runs out of controls as soon as you place
one on the form another awaits you on the tool box ready to be placed as
needed.

What is Visual Basic?

Visual Basic is a high level programming language which evolved from the earlier
DOS version called BASIC. BASIC means “Beginners All-purpose Symbolic
Instruction Code”. Visual Basic is an example of a graphical-based language.

A graphical-based language allows the user to work directly with graphics. It is a


very easy programming language to learn. Different software companies produced
different of high-level languages but only a few have achieved broad acceptance,
for example (QBASIC, FORTAN and Pascal). However, people prefer to use
Microsoft Visual Basic today, as it is a well-developed programming language and
supporting resources are available everywhere. Visual Basic is a Microsoft
Windows Programming language. Visual Basic programs are created in an
Integrated Development Environmental (IDE).

The IDE allows the programmer to create, run and debug Visual Basic programs
conveniently. IDEs allows a programmer to create working programs in a fraction
of the time that it would normally take to code programs without using IDEs.

Visual Basic, derived from the Basic language, is an object-based and event driven
programming language from Microsoft. This language is relatively easy to learn. It
enables you to create GUI (Graphical user interface) applications easily using the
Rapid Application Development (RAD) technique. The one most interesting
feature of this language is that it comes with a designer called Integrated
Development Environment (IDE). The easy-to-use tools of the IDE enable you to
easily create buttons, textbox, and other controls for your desktop application.
Visual Basic 6.0 is a very powerful programming language. It enables GUI
application development, provides access to databases and enables the creation of
ActiveX controls. In addition, Visual Basic 6 is Event-driven because we need to
write code in order to perform some tasks in response to certain events. The events
usually comprises but not limited to the user's inputs. Some of the events are load,
click, double click, drag and drop, pressing the keys and more. We will learn more
about events in later lessons. Therefore, a VB6 Program is made up of many
subprograms, each has its own program code, and each can be executed
independently and at the same time each can be linked together in one way or
another. Start a New Project Run the Visual Basic software from the list of
programs or a desktop shortcut icon.

Click "Standard EXE". Start a Standard .exe type of project. In the beginner level,
you will only learn about this type of project. Other project types on this window
are for the advanced learners. You can do a lot of things implying VB6 is giving
you enough power in your hand through these different project types.

Click "Standard EXE". Start a Standard .exe type of project. In the beginner level,
you will only learn about this type of project. Other project types on this window
are for the advanced learners. You can do a lot of things implying VB6 is giving
you enough power in your hand through these different project types.

The Integrated Development Environment

After this, the main workspace appears where you will develop your application
with the tools in IDE (Integrated Development Environment). It is very important
to know the names of all the elements of this development environment. The tools
available here makes it very easy for you to develop an application. The VB6 IDE
provides you many tools in one place. You can add a control on the form of your
choice, set a property of an object from the Properties Window on the right hand
side, set the form layout and many more things that you can use alongside your
coding. You can even fill the ToolBox with lots of additional controls.

Features of Visual Basic 6.0:

Visual Basic was designed to be easily learned and used by beginner


programmers. The language not only allows programmers to create simple GUI
(graphical user interface) applications, but can also develop complex applications.
Programming in VB is a combination of visually arranging components or controls
on a form, specifying attributes and actions of those components, and writing
additional lines of code for more functionality. Since default attributes and actions
are defined for the components, a simple program can be created without the
programmer having to write many lines of code. Performance problems were
experienced by earlier versions, but with faster computers and native code
compilation this has become less of an issue, the following are some interactive
features used in Visual Basic:

• Create user Interface using design tools

• Add drawings to the forms

• Set properties for the individual object on the form


• Build an executable file

• Debug the applications

• Examine the objects in the forms

• Work with data in the programs (ODBC)

• Add more functionality to the program by writing code

• Publishing the project as standard EXE program.

What programs can you create with Visual Basic 6?

With VB 6, you can create any program depending on your objective. For example
you can create educational programs to teach business, economics, engineering,
computer science, accountancy, financial management, information system and
more to make teaching more effective and interesting. If you are in business, you
can also create business programs such as inventory management system, point-of-
sale system, payroll system, financial program as well as accounting program to
help manage your business and increase productivity.

The Importance of Visual Basic Program

Languages like Basic and Pascal depend on variables and procedures to build the
applications .This is why it is called procedural languages. The new approach is
called object programming for visual programs like Visual Basic and Visual C++
and others. In this programming approach everything (form, command buttons,
controls) is an object. The reasons for of implementing Visual Basic program are
listed as follows:

1- It uses integrated development environment (IDE) which is easier for the


user to minimize code writing.
2- All visual programs follow the same concepts, therefore the user will
become more familiar with visual approach for other visual languages.
3- It provides Input box and Output box as an interactive windows with user.
4- It is able to connect to Internet, and to call Explorer.
The Visual Basic 6 Integrated Development Environment

Before you can program in VB 6, you need to install Visual Basic 6 in your
computer. On startup, Visual Basic 6.0 will display the following dialog box
You can choose to start a new project, open an existing project or select a list of
recently opened programs. A project is a collection of files that make up your
application. There are various types of applications that 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 Visual Basic 6 programming environment.

Project is a collection of files that make up your application. There are various
types of applications that we could create To exit from Visual Basic and return
to Windows is like exit from most Windows applications. There are three ways
to close the Visual Basic as stated below.

1- Click on close button icon that appears in the upper-left corner of the screen.
2- Press Alt+F4
3- Select File >Exit

The IDE (integrated development environment) consists of many elements. Some


elements are displayed when Visual Basic is started (By default) as in the
following figure. Other elements are displayed if the user requires them. We will
list some of these elements.

Elements of Integrated Development Environmental

a. Menu Bar: It contains a standard command like: File, Edit, View, Window, Help
menus, and specific command such as: Project, Format, or Debug menus.

b. Toolbar: it contains the most commonly used commands (button), if clicked an


action represented by that button is carried out.

c. ToolBox: it contains a collection of tools that are needed for project design.
d. form Designer: it is a window for each form to customize the designed interface
of the application. Using the form designer, the user can add controls, graphics,
and text to create the desired form appearance.

e. Properties Window: it is a List of properties settings for a selected form or a


control. These properties are characteristics (such as size, visible, or color) of the
selected object it provides an easy way to set properties.

f. Project Explorer Window: it is a list of the forms and modules for the current
projects. It is a hierarchical tree- branch structure, where the project at top of tree
and other parts like forms, modules) descend from this tree.

g. Form Layout Window: The Form Layout window is a small screen. Which is
used to reposition the form of the application so that it appears in proper place
when project is run?

Six windows appear when you start Visual Basic:

1. The Main Window consists of the title bar, menu bar, and toolbar. The title bar
indicates the project name, the current Visual Basic operating mode, and the
current form. The menu bar has drop-down menus from which you control the
operation of the Visual Basic environment. The toolbar has buttons that provide
shortcuts to some of the menu options. The main window also shows the
location of the current form relative to the upper left corner of the screen
(measured in twips) and the width and length of the current form.
2. The Form Window is central to developing Visual Basic applications. It is
where you draw your application.

3. Toolbox Controls Contains a collection of tools that are needed for project
design as shown in. To show the toolbox press View> toolbox icon. The user
can place the tool on form, and then work with the tool. To place the tool on
form: click on tool>draw tool to form > the tool appears on form or double
click on tool then the tool appears on form.

Label
The label control is used to display text. It is also used to label other controls.
The end user cannot edit the label text.

TextBox

The TextBox control contains characters. End-users can edit the characters
contained in the TextBox.
CommandButton
The CommandButton control is simply a button that we see in our daily-use
software. When the end-user clicks the CommandButton, the program behaves
according to the code assigned in the CommonButton.
Option Button
This control enables the end-user to select one among several options. Only one
option button among others in a group can be on at the same time. You can
name an option using the Caption property.
CheckBox
The CheckBox control is used to make a yes/no or true-false selection. You
can check more than one CheckBox at the same time that let you make multiple
choices. You can label this control using the Caption property.
VscrollBar & HscrollBar
VscrollBar and HscrollBar controls let you create Vertical scroll bar and
Horizontal scroll bar respectively.
Frame
The Frame control is used as a container of other controls. This is also used to
group different controls especially in Option Button controls when you wish to
select more than one option. The Caption property associated with it is useful to
label the frame.
ListBox & ComboBox
The ListBox control contains a number of items. The user can select one or
more items from the list. The comboBox control has the feature of ListBox and
TextBox. This control does not support multiple selections.
DriveListBox, DirListBox & FileListBox
These controls are often used together to perform file related tasks like opening
or selecting files that are stored in the secondary memory.
Timer
The Timer control is not visible on the form when you run the program. It is
used to execute lines of code repeatedly at specific intervals. The Data Control
The Data control is used for database programming.

4. The Properties Window is used to establish initial property values for objects.
The drop-down box at the top of the window lists all objects in the current
form. Two views are available: Alphabetic and Categorized. Under this box are
the available properties for the currently selected object.
BackColor and ForeColor
The BackColor property sets the background color of an object while the
ForeColor property changes the foreground color used to display text. You can
set these properties either from Properties Window or you may wish to set in
run-time.

Font
You can set the font property from the Properties Window.

Caption
It sets the text displayed in the object's title bar or on the object. 'Caption'
property of form sets the form's title text. The text to be displayed on label is
set.
Text
It sets the text in a TextBox. Example: Text1.Text = "New program" Here the
text string is assigned to Text1.Text.
The Left, Top, Width and Height properties
1. The Left Property sets the distance between the internal left edge of an object
and the left edge of its container.
2. The Top Property sets the distance between the internal top edge of an object
and the top edge of its container.
3. The Width Property sets the width of an object.
4. The Height Property sets the height of an object.

Visible
Determines whether an object is visible or hidden.

Example: Label1.Visible = False

Enabled
Determines whether an object can respond to user generated events.
Example:
Text1.enabled=False
MousePointer and MouseIcon
The MousePointer property sets the type of mouse pointer over an object. The
values of MousePointer property are
0- Default
1- Arrow
2- Cross
3- I-Beam
4- Icon
5- Size etc.

The MouseIcon property sets a custom mouse icon from your files.

TabIndex and TabStop

The TabStop property indicates whether the user can use the TAB key to give the
focus to an object. You can give focus to the objects pressing the TAB key in the
daily use software applications. The TabIndex property sets the tab order of an
object.

Example:

Command3.TabIndex = 0

Command2.TabIndex = 1

Command1.TabIndex = 2

When you press the TAB key, the focus will be given on Command3 first, then on
Command2 and at last on Command1.

Control Box indicates whether a control-menu box is displayed on the form at run
time. If this property is set to False, the Close Button, Minimize Button and
Maximize Button are not shown on the form.

ShowInTaskBar

Determines whether the form appears in the windows taskbar.

5. The Form Layout Window shows where (upon program execution) your form
will be displayed relative to your monitor‟s screen
6. The Project Window displays a list of all forms and modules making up your
application. You can also obtain a view of the Form or Code windows (window
containing the actual Basic coding) from the Project window.

As mentioned, the user interface is „drawn‟ in the form window. There are two
ways to place controls on a form:
1. Double-click the tool in the toolbox and it is created with a default size on
the form. You can then move it or resize it.
2. Click the tool in the toolbox, then move the mouse pointer to the form
window. The cursor changes to a crosshair. Place the crosshair at the upper left
corner of where you want the control to be, press the left mouse button and
hold it down while dragging the cursor toward the lower right corner. When
you release the mouse button, the control is drawn.
To move a control you have drawn, click the object in the form window and
drag it to the new location. Release the mouse button.
To resize a control, click the object so that it is select and sizing handles appear.
Use these handles to resize the object.

Code Editor Window: Code Editor Window is used to write a VB code for an
application. For each form there is a separate code editor window. It is
displayed when user clicks on form or object in form.

To Create an Application:
The title of program includes the name of project, and when the user first starts
the program it takes a defaulted value (project1).
The following steps are required to create an application in Visual Basic 6.0:
1) Select type of project New or Exciting. A form automatically appears in the
form design .The basis for any application's interface is the form that user
should create. User can add other forms to the project (to add another form
select project menu>add form).
2) To add objects (controls) to the form use the ToolBox.
3) Set the properties for the objects through properties window.
4) Write code. The Visual Basic Code consists of statements, and declarations.
The code for an application can be written on the Code Editor window. In this
window user can view and edit quickly any of the code.
5) Run the Application. To run the application, click the Start button on the
toolbar, or press F5.
6) Stop. To stop running the application and return to visual basic program
click on stop button in tool bar.
7) Check if there is an error, return to step 3, otherwise continue.
8) Save project.
9) Exit

Concept of Event Driven Programming

Visual Basic is an event-driven programming language. Before proceeding to


the next chapter, it is very important to have a good concept of event-driven
programming. The common events are Click, DblClick, Load, MouseMove,
MouseDown, MouseUp, KeyPress, KeyUp, KeyDown, GotFocus, LostFocus,
etc. When you click, press a key, move the mouse or fire other events, the

What is event driven programming?

The event-driven programming revolves around recognizing the occurrences of


events and then responding to those events by taking appropriate actions. In event-
driven programming an application is build up as a series of responses to user-
events.

Why VB is called ‘Event-Driven’ programming language?

In traditional or procedural application, the application itself determines which


portion of code is to be executed and in what sequence. Generally execution starts
with the 1st line of code and follow the coding sequence define in the application.
Whereas application written in VB are ‘Event-Driven’. In an event-driven
application the code doesn’t follow a pre determined path rather it execute
different code sections in response to events.

Event can be triggered by user’s action, by message from system, other


applications or even from the application itself. The sequences of these events
determine the order in which the code execute and associated with the objects of
application. They either act on an object or are triggered by an object to control the
flow of execution when it is running. That is why VB called Event-Driven
programming language.

Common Events of Visual Basic Controls

Events are what happen in and around your program. For example, when a user
clicks a button, many events occur: The mouse button is pressed, the
CommandButton in your program is clicked, and then the mouse button is
released. These three things correspond to the MouseDown event, the Click event,
and the MouseUp event. During this process, the GotFocus event for the
CommandButton and the LostFocus event for whichever object previously held the
focus also occur. Again, not all controls have the same events, but some events are
shared by many controls. These events occur as a result of some specific user
action, such as moving the mouse, pressing a key on the keyboard, or clicking a
text box. These types of events are user-initiated events and are what you will write
code for most often. Events common to most VB controls are described in the table
below.
Q.2 Explain the elements of the User Interface?

Ans.: The user interface is what appears in the application’s window when it runs.
It consists of various elements with which the user can interact and control the
application. The first element of the user interface is the Form.

(i) Picture Box: This control is used to display images, and the images are set
with Picture property
(ii) Label: This control displays text on a Form that the user can’t edit.
(iii) Text Box: It displays text that the user can edit.
(iv) Frame: It is used to draw boxes on the Form and to group other elements.
(v) Command Button: It is the most common element of the Windows
interface. It represents an action that is carried out when the user clicks the
button.
(vi) Check Box: It presents one or more choices that the user can select.
(vii) Option Button: Also called as radio buttons, appear in groups, and the user
can choose only one of them.
(viii) Combo Box: It is similar to the List Box control, but it contains a text Edit
field. The user can choose an item from the list or enter in the Edit field.
(ix) List Box: It contains a list of options from which the user can choose one or
more. The user can scroll the list to locate an item.
(x) The Horizontal and Vertical Scroll Bars: The users specify a magnitude by
scrolling the control’s button between its minimum and maximum value.
(xi) Timer: It is used to perform tasks at regular intervals.
(xii) File System Controls: These controls are used to add file handling
capabilities to your application.
(xiii) Image: It is similar to the Picture Box control in that it can display images,
but it supports only a few features of the Picture Box control and requires
fewer resources.
(xiv) Data: It provides point and click access to data stored in data- bases.
(xv) OLE: It is a window you can place on your Form to host documents from
other applications, such as Microsoft Word or Excel.
What do you mean by “Integrated Development Environment”?

In an Integrated development environment we can develop, run, test, and debug


our application that is, an IDE has three distinct states - Design, Run, and Debug.
The visual basic provide an IDE which also has three distinct states, the current
state appear in the title bar. The VB IDE composed of these parts:-

1. The menu bar

2. The tool bar

3. The project explorer

4. The properties window

5. The form layout window

6. The tool box

7. The form designer

8. The code window

“Visual Basic provides us a complete set of tools to specify Rapid Application


Development (RAD)”. – Justify. In the early days of computer programming even
a single program could take days or even weeks to complete. When Visual Basic
was first introduced in 1991, it revolutionized programming we no longer needed
to write code to create a user interface, and we no longer needed to worry about
memory management. This new way of programming was known as Rabid
Application Development, or RAD. The main benefit of RAD programming is
increased productivity – Visual Basic of 6.0 has many features that can help us to
create better applications, faster than ever before, the following are few of features

1. Code snipper ->small block

2. Intelligence

Q.3 What are the common properties of the Controls?

Ans.: The following properties apply to most of the objects:


Name: It sets the name of the control, through which you can access the control’s
properties and methods.

Appearance: It can be 0 for a flat look or 1 for a 3-D look.

Back Color: It sets the background color on which text is displayed or graphics are
drawn.

Fore Color: It sets the foreground color Object.

Font: It sets the face, attribute, and size of the font used for the text on the control.

Caption: It sets the text that is displayed on many controls that don’t accept input,
for example, the text on a Label control, the caption of a Command Button control.

Text: It sets the text that is displayed on the controls that accept user input, for
example, the TextBox control.

Width & Height: These properties set the control’s dimensions.

Left & Top: These properties set the coordinates of the control’s upper-left corner,
expressed in the units of the container.

Enabled: By default, this property’s value is True, which means that the control
can get the focus.

Visible: Set this property to False to make a control invisible.

Immediate Window

The immediate window has three purposes. The first is for program output. You
can use the: Debug.Print command to send something to the Immediate Window.
This can be helpful when debugging some code to see what a variable's value is at
a certain point, or to provide any other useful information. The other half is to
provide immediate input. Let's say your code is running along and stops for some
reason. Perhaps a variable has the wrong value and it's causing an error. You could
stop, correct the code, and restart, but sometimes that takes too long or we can't
easily start over. You can change type any line of code into the Immediate Window
and upon hitting Enter, the code will execute. This could be as simple as selecting
a Range, changing a variables value, or anything else where you want to have the
code immediately do something. Benefit here is that doing stuff in Immediate
window doesn't affect the code that is currently paused.
The last purpose is to query something. If you put a question mark before a line of
code, the window will try to return the result. This could be used to get the value of
a variable in code that is currently running, or if you wanted to know the value of a
cell,etc.
Examples of lines in immediate window

You might also like