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

Sudhanshu Rai Visual Basic Assignment

Visual Basic (VB) is an event-driven programming language and environment from Microsoft that provides a graphical user interface (GUI) which allows programmers to modify code by simply dragging and dropping objects and defining their behavior and appearance. VB is derived from the BASIC programming language and is considered to be event-driven and object-oriented. VB is intended to be easy to learn and fast to write code with; as a result, it is sometimes called a rapid application development (RAD) system and is used to prototype an application that will later be written in a more difficult but efficient language.

Uploaded by

Vinay sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

Sudhanshu Rai Visual Basic Assignment

Visual Basic (VB) is an event-driven programming language and environment from Microsoft that provides a graphical user interface (GUI) which allows programmers to modify code by simply dragging and dropping objects and defining their behavior and appearance. VB is derived from the BASIC programming language and is considered to be event-driven and object-oriented. VB is intended to be easy to learn and fast to write code with; as a result, it is sometimes called a rapid application development (RAD) system and is used to prototype an application that will later be written in a more difficult but efficient language.

Uploaded by

Vinay sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 33

PUNJABI UNIVERSITY ,

PATIALA

VISUAL BASIC

SUBMITTED TO:-
MRS. AMANDEEP KAUR

SUBMITTED BY:-
SUDHANSHU RAI
B.SC.(C.S.M.)
18481104
Visual Basic (VB)
Visual Basic (VB) is an event-driven programming
language and environment from Microsoft that provides
a graphical user interface (GUI) which allows
programmers to modify code by simply dragging and
dropping objects and defining their behavior and
appearance. VB is derived from the BASIC programming
language and is considered to be event-driven
and object-oriented.
VB is intended to be easy to learn and fast to write code
with; as a result, it is sometimes called a rapid application
development (RAD) system and is used
to prototype an application that will later be written in a
more difficult but efficient language.
The last version of VB, Visual Basic 6, was released in
1998, but has since been replaced by VB .NET, Visual
Basic for applications (VBA) and Visual Stuido .NET. VBA
and Visual Studio are the two frameworks most
commonly used today.
Visual Basic is an object-oriented programming
development system for creating applications that run
under any of the Microsoft Windows environments.
It has the following two major components:  
1. An extensive collection of prewritten tools, called
controls. These controls are accessible as icons within a
graphical programming environment for creating
customized windows components (e.g., menus, dialog
boxes, text boxes, slide bars, etc.).  
2. A complete set of program commands, derived from
Microsoft’s implementation of the classical Basic
programming language. The command set includes
features that embrace contemporary programming
practices.  
The overall approach to Visual Basic programming is
twofold:  
1. Create a user interface that is appropriate to the
particular application at hand.  
2. Add a group of Basic instructions to carry out the
actions associated with each of the controls. 
 
Visual Basic is a third-generation event-driven
programming language first released by Microsoft in
1991. It evolved from the earlier DOS version called
BASIC. BASIC means Beginners' All-purpose Symbolic 
Instruction Code. Since then Microsoft has released
many versions of Visual Basic, from Visual Basic 1.0 to
the final version Visual Basic 6.0. Visual Basic is a user-
friendly programming language designed for beginners,
and it enables anyone to develop GUI window
applications easily. 
In 2002, Microsoft released Visual Basic.NET(VB.NET) to
replace Visual Basic 6. Thereafter, Microsoft declared
VB6 a legacy programming language in 2008.
Fortunately, Microsoft still provides some form of
support for VB6. VB.NET is a fully object-oriented
programming language implemented in the .NET
Framework. It was created to cater for the development
of the web as well as mobile applications. However,
many developers still favor Visual Basic 6.0 over its
successor Visual Basic.NET. 
Microsoft’s Visual Basic is an evolution of the BASIC
programming language that is designed to be used with a
richly featured programming interface called an
Integrated Development Environment (IDE). Prior to the
development of IDEs, programming with languages like
BASIC relied heavily upon the DOS command-line.
Programmers were required to write out their code
manually and use DOS to compile their programs into
executable files—a somewhat arduous process with
much room for error. An IDE, however, simplifies the
process dramatically by providing a unified interface that
facilitates coding and allows one-click compilation into an
executable file. 
Coding with an IDE can be done manually or by dragging
and dropping popular commands and procedures. This is
a significant difference from languages like C++ where
the user is responsible for writing code from scratch. The
IDE can also check for potential errors in code and
suggest improvements and corrections. Because of its
simplicity, Visual Basic tends to be very approachable for
beginning programmers interested in writing simple
programs. 
As a programming language designed by Microsoft,
Visual Basic is used primarily in a Windows environment
for writing system-specific applications. In , Microsoft
implemented Visual Basic within its .NET framework,
dubbing the new release Visual Basic.NET. For many
users, however, it is worth pointing out that Visual
Basic .NET is often still referred to as Visual Basic today
for simplicity. 
 
 
 
Visual Basic features and characteristics

VB is a GUI-based development tool that offers a faster RAD


than most other programming languages. VB also
features syntax that is more straightforward than other
languages, a visual environment that is easy to understand and
high database connectivity.   
Visual Basic was designed to be a complete programming
language that contained ordinary features, such
as string processing and computation. The visual environment
is characterized by a drag-and-drop feature which allows
programmers to build a user interface that is easy to use, even
for developers with minimum experience. 
While these features of VB are advantageous, there are others
that can have a negative effect. The VB programming
environment requires a large amount of memory, both for the
initial installation and to run efficiently afterwards. The
graphical features of the programming tool take up a large
amount of space and require a significant amount of memory. 
Furthermore, Visual Basic is not useful when developing
programs that require a lot of processing time, like games, and
the use of VB is restricted to Microsoft operating systems (OS). 
Finally, with C languages, programmers can feasibly locate and
use the defined values for variable data in a computer program
at declaration time. This initialization practice is something that
isn't easily done with VB. 
 
 
How Visual Basic is used
The structure of VB is designed to allow programmers to use the
environment to write executable files (exe files). Also, using VB,
developers can create programs that can be utilized as a front end to
databases. VB tools can help programmers develop applications or
complete software while still allowing them to modify and revise their
work accordingly. 
The most popular type of Visual Basic in use today is VBA. VBA is a
version of Visual Basic that can be used to program Microsoft
Office apps, such as Excel and PowerPoint. However, it can only be used
to modify existing apps; VBA cannot be used to create new apps. 
Typical users engage VBA to make repeated, everyday tasks less
monotonous through the use of macros. Macros automate almost any
activity -- such as performing word and data processing or generating
custom charts and tables. For example, a typical user might write a
macro that allows them to create and fill a spreadsheet with a single
click. Computer professionals use VBA and macros in more complicated
ways. Programmers will often write macros that can replicate large
portions of code or define specific languages. 
Businesses and organizations can use VBA to customize Excel for their
unique purposes, such as pulling certain statistics or information from
a spreadsheet. Businesses and organizations can also use VBA
externally, or in non-Microsoft applications, by applying a technology
called a component object model (COM) interface that enables
commands to communicate across computer boundaries. This allows
VBA to be used on an enterprise-specific application. 
Benefits of Visual Basic

The BASIC programming language, which VB is derived


from, is simple and easy to work with, especially when
writing exe files. 
However, VB becomes extremely beneficial when used
with Microsoft's COM interface. The COM components
can be written in various languages and then integrated
using VB. Additionally, VB provides not only a
programming language, but an integrated development
environment (IDE) that has been written and optimized
to best support RAD. This allows programmers to easily
build GUIs and connect them to functions within the
application. 
Furthermore, the Visual Basic IDE provides views of the
management of the program structure that are easy to
understand. 
Overall, VB enables the rapid development of Windows
based applications while also assisting in the access of
databases by using ActiveX data objects (ADO) while
allowing programmers to use ActiveX control and various
objects. 
What programs can you create with
Visual Basic ? 

In Visual Basic, you can create any program depending on


your objective. For math teachers, you can create
mathematical programs such as Geometric
Progression, Quadratic Equation Solver, Sim ultaneous
Equation Solver ,Prime Number Tester, Factors
Finder, Quadratic Function Graph Plotter and so on. For
science teachers, you can create simulation programs
such as Projectile, Simple Harmonic Motion, Star War 
etc. If you are in business, you can also create business
applications such as inventory management
system , Amortization Calculator , investments calculator,
point-of-sale system, payroll system, accounting program
and more to help manage your business and increase
productivity. For those of you who like games , you can
create programs such as slot machine, reversi, tic tac
toe and more. Besides, you can create multimedia
programs such as Smart Audio Player, Multimedia Player 
and more. Indeed, there is no limit to what program you
can create ! We offer many sample codes in our tutorial.

 
Visual Basic for Applications
VBA is not an entirely different language from Visual Basic.
Rather, as the name suggests, VBA is a specialized
implementation of the Visual Basic language that is designed to
be used within existing applications. Often bundled with
Microsoft applications like the Office Suite and third-party
programs like AutoCAD, VBA is designed to provide simple
programming options to extend the functionality of popular
programs. 
The key word is “extend.” VBA cannot compile into a system
executable file on its own. Rather, it requires an interpreter to
read the “P-code” created through the compilation process. A
VBA program can be embedded in a Microsoft Word document,
for example, but cannot stand on its own as a program run
from the Windows Start Menu. For users wishing to write
programs from scratch, Visual Basic would normally be used
rather than VBA. 
As with other intermediate language environments like Java,
VBA suffers a speed disadvantage when compared to the native
programs written in Visual Basic. The reason for this is that VBA
requires the additional step of interpretation by another
program. The extra steps and corresponding system resources
required to execute VBA programs mean that VBA is normally
not used if speed is an issue 
EVENTS AND EVENT PROCEDURES

 In traditional computer programs, the actions are carried


out in a prescribed order. This order may be sequential,
corresponding to the order in which the instructions are
written, or it may depend on the outcome of one or
more logical tests. In either case, the order of execution
is determined internally within the program. Visual Basic,
on the other hand, is based upon an event-driven
paradigm, in which each feature included within the
program is activated only when the user responds to a
corresponding object (i.e., an icon, a check box, an option
button, a menu selection, etc.) within the user interface.
The program’s response to an action taken by the user is
referred to as an event. Note that the user initiates the
event, but it is the program’s response that actually
defines the event. The group of Basic commands that
brings about this response is called an event procedure 

OBJECT-RELATED CONCEPTS
 In addition to events and event procedures, you must
understand the meaning of each of the following terms: 
 Forms: In Visual Basic, a window is called a form. Each
form includes a title bar at the top. A form may also
include a menu bar, a status bar, one or more toolbars,
slide bars, etc. A user area (called a client area) occupies
the remaining space within the form. Some applications
are based upon a single form, while others require two
or more forms.  
 
Controls: The icons with which the user interacts are
called controls. Commonly used controls include
command buttons, option buttons, check boxes, labels,
text boxes, picture boxes and menus. The user will
typically activate a control (e.g., click on a command
button) to produce an event.  
 
The image below represent all some of the common
controls of visual basic.
Objects: Forms and controls are referred to collectively
as objects. Most objects are associated with events;
hence, objects may include their own unique event
procedures. Objects are also associated with their own
properties and methods. An object is a combination of
code and data that can be treated as a unit. An object
can be a piece of an application, like a control or a form.
An entire application can also be an object. 
When you create an application in Visual Basic, you
constantly work with objects. You can use objects
provided by Visual Basic, such as controls, forms, and
data access objects. You can also use objects from other
applications within your Visual Basic application. You can
even create your own objects and define additional
properties and methods for them. Objects act like
prefabricated building blocks for programs — they let
you write a piece of code once and reuse it over and
over. 
Each object in Visual Basic is defined by a class. A class
describes the variables, properties, procedures, and
events of an object. Objects are instances of classes; you
can create as many objects you need once you have
defined a class  

 Properties: Objects include properties that generally


define their appearance or behavior. The choice of
properties depends on the type of object. For example,
the name, caption, height, width, background color,
location and font are some of the more common
properties associated with a command button. 
 

 Methods: Some objects also include special program


statements called methods. A method brings about some
predefined action affecting the associated object. For
example, show is a method that can be used with a
hidden form to make it visible. 
For example, Add is a method of the ComboBox object
that adds a new entry to a combo box. 
The following example demonstrates the Start method of
a Timer object. 
 
Dim safetyTimer As New System.Windows.Forms.Timer 
safetyTimer.Start() 
 
The Visual Basic Program Development Process
Visual basic or VB is an “event driven programming
language” and “integrated development environment” of
Microsoft. “Graphical user interface” is used with a basic
programming language; it is the first product to provide a
graphical programming environment for developing a
user interface.
Steps to create a visual basic project
• Open Microsoft Visual Basic 2010 (Using Microsoft Visual
Studio 2010).
• Click File menu, select File → New project
• Select “Windows Forms Application” in the pop-up New
Project window and name the project
• Click File menu → Save All
In the form add the required controls and set the
required properties, add the required code to develop an
application, click the run icon or press F5 button to run
the application program.
INTEGRATED DEVELOPMENT ENVIRONMENT
An integrated development environment (IDE), also
known as integrated design environment and integrated
debugging environment, is a type of computer software
that assists computer programmers to develop software.
In the case of Visual Basic .NET, that IDE is Visual
Studio. Visual Basic integrates different tools for
designing, coding, compiling and debugging in a single
window which is called Integrated Development
Environment. It is called integrated because we can
access all the tools from one screen that is called an
interface.
The Visual Studio integrated development environment
is a creative launching pad that you can use to edit,
debug, and build code, and then publish an app. An
integrated development environment (IDE) is a feature-
rich program that can be used for many aspects of
software development.
The Visual Basic IDE has three distinct states:
 Design Mode: When you are creating or designing an
application is called Design Mode.
 Run Mode: When you are executing an application is
called Run Mode.
 Debug Mode: When you are removing bugs or errors
from an application is called Debug Mode.

The Visual Studio IDE consists of several sections, or


tools, that the developer uses while programming. As
you view the IDE for a new project you generally have
three sections in view:
 The Toolbox on the left.
 The Solution Explorer on the right.
 The Code / Design view in the middle.
Components of visual basic IDE window: –
• Title bar: – A title bar is the horizontal bar located the
top of the screen. It includes the project name, an icon
that closes visual basic at the left and icon that minimize
the group window, change the size of the group or close
visual basic on right. This component common for all
window application.
• Menu bar: – The menu bar is also common for all
document window. It contents command required and
build an application. The main menu items have some
menu items that can be chosen when needed. The list of
menu items in menu bar is explained below:
File: It contains commands for opening , saving, printing
or to make executable files and recently opened projects.
Edit: It contains commands for undo, cut, copy, paste,
find and replace in your project.
View: It contains commands for showing or hiding
components of the IDE.
Project: It contains commands to add, remove forms,
modules, controls etc. in your Project.
Format: It contains command for aligning or resizing
controls.
Debug: It contains commands for debugging in your
project.
Run: It contains commands to start, break and stop the
execution of the project.
Query: It contains commands to create queries.
Diagram: It contains commands for editing database
diagrams.
Tools: It contains commands to open menu editor and
building ActiveX components.
Add Ins: It contains Visual Data Manager.
Window: It contains commands to arrange windows on
the screen.
Help: It helps for project creation
 Tool bar: – The tool bars gives us quick access to
commonly used menu command. Beside the main
tool bar, which is displays by default window the
menu bar, visual basic IDE provides additional tool
bar for specific purpose.
The four built in tool bar are standard, edit, debug and
from editor. By default, standard tool bar appear
immediately below the menu bar.
• Project explorer Window: – The docked on the right
side of the screen and just below standard tool bar, is the
project explorer window. The project explorer window.
Serve as a quick reference to the various element of a
project namely form, class and module. All the objects
that make up the application are packet in a project.
The project explorer window holds the file name for the
file included in our project. A window’s title bar holds the
name our project with .VBP file extension, which is
project one by default until we save it with a new name.
A simple project typical contents one form, which is
window that is designed as part of the program interface.
It is possible to develop any number of forms in a
program.
• Tool box: – The tool box contains the icon of the
control we can place on a form to create the
application’s user interface. By default tool box contains
a pointer icon and twenty other icon of ActiveX controls.
The tool box appear at the left side on screen by default.
User can change its position anywhere on the form. Even
tool box can be turn off on screen. To place a control on
a form, we first select it with a mouse and then move the
mouse over the form. When the mouse is over the form,
the curser turns into a large plus sign, and we can draw
control on the form, just as we would draw a circle using
a drawing application. The size of the circle determines
the size of the control.
• Properties Window: – Every object has properties
associated with it. The properties window is docked
under the project explorer window. The properties
window allows us to assign or change properties
associated with a particular object. Properties are
attributes such as size, position etc. like a form, each
control has its own set of properties. Some properties
like width, height are common to both form and controls,
while other properties are unique to form or control.
• Form layout window: – The form layout window
specifies a form’s position on the screen at run time. The
form layout window appear below the properties
window. It consists of an image representing the screen
and the form’s relative position on the screen. With the
mouse pointer positioned over the form image,+ draw it
to the new location. Note that the mouse pointer
changes shape when moved over the image representing
the form.
• Designer Window(Form Window): – A Designer window
used in visual basic to create project inside the form. A
Designer window appear on screen just like grid of dots
inform of matrix. We can increase or decrease size of
designer window according to our need. By default only
one designer window will appear on screen but more
than one Designer window can be open on the project
window. Out of multiple Designer windows, one window
is called master window and other are called slave
windows. By default first window automatically treated
as master window. But user can change or select any one
window as a master window. Remaining window are
automatically changed to slave window.
• Project window: – Only one project window will appear
on screen when be open visual basic window. This
project window appear beside the form window. User
can not add another project in the current project. By
default name of a project is project1 and its file name is
project1.vbp but user can change project name as well as
project file as needed.
• Code Editor Window: – Normally code window not
appear on screen because it is automatically hidden.
When we double click any control in the form, a code
window will open. Visual basic code window consist of
two list boxes. Both list boxes appear at the top of the
code window. The left most list box is called object list
box and right most list box is called procedure list box.
Object list box allows us to select event procedure
associated with a particular object. The procedure list
box allows us to select the event procedure associated
with a particular type of event such as click, drag drop,
key down, mouse down etc.
• Immediate Window: The immediate window placed at
the bottom of the IDE and it is used for debugging
purpose. During the execution of the project you can
close it and use to change the values of the variables and
also insert statements in code during execution of the
project. In case if the Immediate window is not visible in
an IDE then select View-> Immediate window from menu
bar.
CREATING A PROJECT IN VISUAL BASIC

1. Start Visual Studio.


2. On the Visual Studio File menu, click New Project.
3. The New Project dialog box opens
4. The New Project dialog box provides access to the
major project types available for writing Windows
and Web applications.
5. Click the Windows Forms Application icon in the
central Templates area of the dialog box, if it is not
already selected. Visual Studio prepares the
development environment for Visual Basic Windows
application programming .
6. In the Name text box, type any name you want to
give to the project.
7. Click OK to create the new project in Visual Studio.
Your new project will be created.

NEW PROJECT IS CREATED.


Opening a existing VB Project
To open your project through VB 2010 Express, one way
is to click the “Open Project” link on the Start Page,
which will cause the Open Project dialog box to be
displayed, and you would navigate to your solution file
from there. Now the existing project will open.
Yet another way to open your project from VB 2010
Express is through the File menu, Open Project option.
This works the same way as the “Open Project” link on
the Start Page.
Now you can open your exiting project with this process
also.
Saving a visual basic project:-

1. Choose menu File>Save project OR Ctrl+S then save


File
2. By default any name e.g. form1 is highlighted in file
name text box then press backspace key and enter the
name of form as you want and press save button. The
default extension of form in visual basic is .frm
3. Then save project as dialog box opens and enter the
name of project in file name text box and press save
button. The default extension of project in visual basic
is .vbp
4. Now you can see name of form and project changed in
project explorer window

Running a VB Project

To run the project, choose menu Debug->Start


Debugging OR press F5
or click green arrow button on the toolbar.
During every time execution of the project first form of
the project executed ,to execute the another form right
click the project in the project explorer window and
select project properties and then select the form from
startup.
THANK
YOU…..!!

You might also like