0% found this document useful (0 votes)
34 views105 pages

VB B.com. (CA) Material

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)
34 views105 pages

VB B.com. (CA) Material

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/ 105

SEM: V CLASS: III-B.Com.

CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

VISUAL PROGRAMMING

UNIT – I
Introduction to Visual Basic: Getting Started - Working with Visual Basic – The Initial Visual Basic
Screen –The SDI Environment – Toolbars - The Toolbox and Custom Controls and Components –
Starting a New Project – The Properties Window – Common Form Properties – Scale Properties – Colour
Properties.
UNIT – II:
Building the User Interface: Toolbox – Creating Controls – Name Property - Properties of Command
Buttons - Image Controls - Text Boxes – Labels – Message Boxes - Grid. Anatomy of a VB Application –
The Code Window – Statement in Visual Basic – Variables – Data types – Working with Variables –
Constants – Input-Boxes
UNIT- III:
Display Information on a Form - The Format Function - Picture Boxes – Rich Text Boxes – The Printer
Object - Determinate Loops - Indeterminate Loops – Making Decisions – Select Cases – Nested If- Then
– The GOTO – String Functions – Numeric Functions – Date and Time functions – Financial Functions
UNIT - IV:
Function Procedures – Sub Procedures – Advanced Uses of Procedures and Functions – Lists: One–
Dimensional Arrays – Arrays with more than One–Dimension - Using Lists and Arrays with Functions
and Procedures – The With Statement - Enums – Control Arrays – List and Combo Boxes – Menus –
Menu Editor – MDI Forms.
UNIT – V:
Introduction to Database - Working with Data Control: The Data Control - The Bound Control – Coding
– Data Access Object: Functions of the Jet Database Engine – The DAO Object Model - Crystal and Data
Reports: Crystal Report - Data Report – Creating Multiple Reports

TEXT BOOKS: 1. ―Visual Basic 7 From the Group UP‖, Gray Cornell, Tata McGraw Hill Edition
(Unit-1 to Unit –IV)
2. ―Programming With Visual Basic 6.0, Mohammed Azam, 2nd Edition. (Unit – V)

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 1
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

UNIT -1
Introduction to Visual Basic: Getting Started - Working with Visual Basic – The Initial Visual Basic
Screen –The SDI Environment – Toolbars - The Toolbox and Custom Controls and Components –
Starting a New Project – The Properties Window – Common Form Properties – Scale Properties – Colour
Properties.

INTRODUCTION TO VISUAL BASIC: GETTING STARTED


 Visual Basic is an Event Driven programming language.
 Visual Basic is used to create applications fast, as well as, very easily.
 Visual Basic provides us with a complete set of tools to simplify Rapid Application
Development (RAD).

WORKING WITH VISUAL BASIC 6.0:


i) A Simple Application:
Click Start Programs Microsoft Visual Studio 6.0 Visual Basic 6.0 (or)
Double click the Visual Basic Icon on the desktop.

1. New lets you create new applications by using various wizards or starting from scratch.
2. Existing lets you select and open an existing Visual Basic project.
3. Recent displays a list of Visual Basic projects you've recently opened or created.

 A project is a collection of files that make up your application. A single application might consist of
several files, and the project is the collection of those files.
 Now the New Project dialog box will appear. We are going to create a simple application. So choose
Standard EXE from the New Project dialog box and click the Open button.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 2
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

 Now Visual Basic IDE (Integrated Development Environment) window will appear. It contains
several menus, windows, tool bars and toolbox.

Integrated Development Environment

ii) Using the application wizard:


The application wizard allows the user to insert fully customized standard Windows menu into
application.
To start using Visual Basic's Application Wizard, click on the Application Wizard icon at the
Visual Basic new project dialog box, as shown below

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 3
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Click on the VB Application wizard, the introduction dialog box will appear, as shown in below Figure.
As you are not loading any default setting, just click on the Next button.

After clicking the Next button, the interface type dialog box will be displayed, as shown in below.

Here are the options from which you can select:


1. Multiple Document Interface (MDI) allows your application to contain multiple document
windows. In effect, this interface lets you work with several sets of data in multiple windows
within your program. Each document window is called a child window.
2. Single Document Interface (SDI) limits your application to one open document window at a
time. Most applications that you write will probably be SDI applications.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 4
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

3. Explorer Style lets your application take on a Windows Explorer-like interface with topic
summaries in the left window and details for a selected topic in the right pane.
Type the project name in the textbox below, here I am using MyFirstMenu.
Clicking the Next button will bring up a list of menus and submenus that you can add them to your
application.

Check to select a menu item and uncheck to unselect a menu item as shown in above Figure
Choose all the menus and click next, then will get an interface comprises File, Edit, View and Help
menus.
The Application wizard saves you time by creating an initial toolbar.

The next wizard screen to appear is the Resource screen from which you can elect to use resources
in your program, such as multilanguage text files. Simple programs often do not require external
resources.
For this example, keep the option labeled No checked and click the Next button to continue.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 5
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

The next wizard screen is the Internet Connectivity screen from which you can add an Internet
interface to your program if you want one.
Click finish in the next screen. Now the first project is created.

THE INITIAL VISUAL BASIC SCREEN:


The Visual Basic Integrated Development Environment (IDE) is a program from Microsoft
used to create, test, and deploy Visual Basic (VB) programs.
The VB IDE allows a programmer to write code and test it immediately, converting the source
program to executable code as needed.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 6
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

The Visual Basic development environment contains these programming tools and windows,
with which we construct your Visual Basic programs:
Title bar
Menu bar
Toolbars
Visual Basic toolbox
Form window
Properties window
Project Explorer
Immediate window
Form Layout window

Title bar:
The title bar is the horizontal bar located at the top of the screen.
It gives the name of the application.
In visual basic, the title bar displays: Project1- Microsoft Visual Basic [design]
This is typical windows application that has multiple states, the title bar changes to indicate
important information.
When we run the program the title bar changes as: Project1- Microsoft Visual Basic [run]
When we debug the program the title bar changes as: Project1- Microsoft Visual Basic [break]

Menu bar:

The following Menus are available in Visual Basic IDE.


 File Menu To open and save a new or existing project, to print and to make
a project.
 Edit Menu For all existing requirement Cut, Copy, Paste, Find, Undo, etc
 View Menu To view the various parts of your project.
 Project Menu Inserting or removing forms or objects.
 Format Menu For spacing, Placing and appearance controls in the form.
 Debug Menu To remove the errors.
 Run Menu To compile start and stop a program.
 Tools Menu To add Procedure and to customize the environment for your
project.
 Add-Ins Menu To add tools likes Data Manager, other Wizards, etc.
 Windows Men Arranging appearance of various windows.
 Help Menu For the On-line help facility.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 7
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

THE SDI ENVIRONMENT:


The SDI (Single Document Interface) Environment shown in Figure with the same windows available as in
the default MDI environment, you can move all the different windows around independently, and (usually)
part of your desktop.
Each of the windows in the Visual Basic environment is completely independent of the others.
If you wanted to, you could even move the title bar to the bottom of your screen!
To switch to the SDI environment:
1. Choose Tools|Options.
2. Click on the Advanced tab.
3. Select the SDI Development Environment check box.
The SDI environment will be available the next time you start Visual Basic.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 8
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

TOOLBARS:
Visual basic has multiple toolbars.
The four built in toolbars are
1. Standard
2. Edit
3. Debug
4. Form editor

Standard toolbar:

View Application - Toggles between the host application and the Visual Basicwindow.

Insert Userform - Defaults to a userform but also allows you to insert modules and
procedures.
Save - Saves the application including all the Visual Basic components.
Cut - Removes the selected control or text and places it on the clipboard.
Copy - Copies the selected control or text and places it on the clipboard.
Paste - Inserts the contents of the clipboard at the current location.
Find - Displays the Find dialog box allowing you to search for particular text.
Undo - Reverse the last text editing action.
Redo - Restores the last text editing Undo actions.
Run - Runs the current procedure if the curosr is in a procedure. Runs a userform ifa
userform is currently displayed. Displays the Run dialog box otherwise ??
Break - Stops execution of a program while it is running and switches into breakmode.

Reset - Clears the execution stakc module level variables and resets the project.
Design Mode - Toggles design mode.
Project Explorer - Displays (or toggles) the Project Explorer window.
Properties Window - Displays (or toggles) the Properties window.
Object Browser - Displays (or toggles) the display of the Object Browser window.

Toolbox - Toggles the display of the toolbox that contains userform controls. Thisis only
available when a userform is active.
Help - Opens the Office Assistant.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 9
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Edit toolbar:

List Properties / Methods - Displays a drop-down list in the code window that contains all
the properties and methods available for the object that precedes the period (.).

List Constants - Displays a drop-down list in the code window that contains all theconstants
that are valid choices for the property that precedes the equal sign (=).
Quick Info - Provides the syntax for a variable, method, function or procedurebased on
the location of your position.
Parameter Info - Displays a popup in the code window containing information
about the parameters of the function in which the pointer is located.
Complete Word - Accepts the characters that the editor has automaticallyappended as
you were typing.
Indent - Shifts all the lines (in the current block) to the next tab stop. No shortcutkey by
default but you could add one.
Outdent - Shifts all the lines (in the current block) to the previous tab stop. Noshortcut
key by default but you could add one.
Toggle Breakpoint - Toggles the insertion of a breakpoint at the current line.
Comment Block - Adds the comment character (‘) to the beginning of each line inthe
current selection.
UnComment Block - Removes the comment character (‘) from the beginning ofeach line
in the current selection.
Toggle Bookmark - Toggles the insertioon of a bookmark on or off for the activeline.

Next Bookmark - Moves the focus to the next bookmark in the bookmark stack.
Previous Bookmark - Moves the focus to the previous bookmark in the bookmarkstack.

Clear All Bookmarks - Removes all the breakpoints from the active project (or allprojects
??).

Debug Toolbar

Design Mode - Toggles design mode.

Run / Continue - Run switches from design time to run time. Continue switches from break modeto run
time. When in break mode the name of the button changes to Continue (Ctrl + F8).
Break - Switches from run time to break mode.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 10
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Reset - Switches from break mode or run time to design time.

Toggle Breakpoint - Defines a line in a module where Visual Basic suspends execution of theapplication
(F9).
Step Into - Runs the next executable line of code in the application and steps into procedures (F8).

Step Over - Executes the next executable line of code in the application without stepping intoprocedures
(Shift + F8).
Step Out - Executes the remaining lines of the current procedure and breaks at the next line in thecalling
procedure (Ctrl + Shift + F8) - check
Locals Window - Displays the Locals window to show the values of all the local variables.

Immediate Window - Displays the Immediate window to allow you to to run code or query valueswhile the
application is in break mode (Ctrl + G).
Watch Window - Displays Watch window to show values of selected expressions.

Quick Watch - Displays the Quick Watch window to show the values of expressions and variableswhile the
application is in break mode (Shift + F9).
Call Stack - Displays the Call Stack dialog box while in break mode that shows all procedures thathave been
called but not yet run to completion.

Form editor tool bar:


We can use form editor toolbar while designing forms.

Customizing toolbar:
We can build our own custom toolbars or modify the displaying on any existing toolbar.
For example: if we want to add text description for a specify tool follow the steps
1. Right click inside the toolbar which want to customize
2. From the content menu that pops up choose Customize. The customize dialog box opens.
3. Right-click on the button we want to customize. This displays a pop up menu, and choose
Text only from that popup menu

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 11
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Now if we want to build a toolbar from scratch.


1. Right click inside a toolbar and choose customize
2. Choose New
3. Give a name to your new toolbar in the dialog box that pops up and click on OK.

4. Now a tiny toolbar pointed to here in the center of the customize dialog box.

THE TOOLBOX AND CUSTOM CONTROLS AND COMPONENTS:


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

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 12
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Control Description
Pointer Provides a way to move and resize the controls form
PictureBox Displays icons/bitmaps and metafiles. It displays text or acts as a
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 OptionButton control which is a part of an option group allows the
user to select only one option even it displays mulitiple choices.
ListBox Displays a list of items from which a user can select one.
ComboBox Contains a TextBox and a ListBox. This allows the user to select
an 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
DriveListBox Displays the valid disk drives and allows the user to select one of
them.
DirListBox Allows the user to select the directories and paths, which are
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
Image used to display images such as icons, bitmaps and metafiles. But
less capability than the PictureBox
Data Enables the use to connect to an existing database and display
information from it.
OLE Used to link or embed an object, display and manipulate data from
other windows based applications.
Label Displays a text that the user cannot modify or interact with.

To add new components to our toolbox that are already registered with windows, follow the 3 steps:
1. Choose project | component
2. From the dialog box choose which control want to add by clicking in the box that marks the
appropriate component.
3. Click OK

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 13
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

To add another tab,


1. Right-click on the toolbar
2. Choose Add tab from the context menu that pops up.
3. Give the new tab name.
To actually add the controls, we can either,
1. Drag the control from an existing tab, or
2. Click on the tab in order to make it active, and then add the new components through the
components dialog box.

The Initial Form window:


It takes part of the center of the screen.
We can customize the form window by adding controls and changing its size.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 14
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Project Explorer:
Visual Basic organizes applications into what it calls projects.
Each project can have multiple forms, and the code that activates the controls on a form is
stored with the form in separate files.
General programming code shared by all the form in our application can be divided into
different modules, which are also stored separately.
The Project Explorer _is usually located at the far right of the screen.
It contains a Windows Explorer-like tree view of all the customizable forms and general code
(modules) that make up your application.

The three tools in the top of the Project Explorer:


1. View code: Shows the code window
2. View object: Shows the form window
3. Toggle folders: Views or hides the folders in the Project Explorer

Shortcut (pop up) Menus:


1. Toolbox:
The following fig shows the context menu for the toolbox.

The Components item leads to a dialog box that was shown in Figure. The Add Tab item is to add a
new tab to the toolbox when you too many controls to fit easily

2. Toolbar:
If you right-click in the toolbar, you will see a context menu similar to this,

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 15
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

which lists all the toolbars that are available. (The checked ones are the ones that are visible.) Click
on any toolbar in the context menu to display or hide it. As you have seen, you can click on the
Customize option in order to add your own toolbars or to customize an existing toolbar.

3. Form Designer and Code Window:


Here is the context menu for the form designer:

The context menu for the code designer

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 16
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

4. Project explorer:
There are actually two context menus available for the Project Explorer window: one for right-
clicking on a project or one of the objects, such as a form, and one for building a user control. The
functionality of both context menus is similar. The following illustration shows the context menu
when you click on a form:

STARTING A NEW PROJECT:


How will you start Visual Basic?
i) Click Start Programs Microsoft Visual Studio 6.0 Visual Basic 6.0 (or)
Double click the Visual Basic Icon on the desktop.

Now the New Project dialog box will appear.


We are going to create a simple application. So choose Standard EXE from the New Project
dialog box and click the Open button.
Now Visual Basic IDE (Integrated Development Environment) window will appear.
It contains several menus, windows, tool bars and toolbox.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 17
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Integrated Development Environment

Menus:
The following Menus are available in Visual Basic IDE.
 File Menu To open and save a new or existing project, to print and to make a
project.
 Edit Menu For all existing requirement Cut, Copy, Paste, Find, Undo, etc
 View Menu To view the various parts of your project.
 Project Menu Inserting or removing forms or objects.
 Format Menu for spacing, Placing and appearance controls in the form.
 Debug Menu To remove the errors.
 Run Menu To compile start and stop a program.
 Tools Menu To add Procedure and to customize the environment for your
project.
 Add-Ins Menu To add tools likes Data Manager, other Wizards, etc.
 Windows Men arranging appearance of various windows.
 Help Menu For the On-line help facility.

Altering a form:
The user can change the size and location of forms when the form is running or when the
form starts up. VB has ability to make dynamic changes in response to user events.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 18
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

To resize a form at design time.


Move the mouse to one of the hot spots of the form.
In a form, the hotspots are the sides or corners of the form. Mouse pointer changes to double-
headed arrow and the user can change its size and shape.

To resize a form at run time.


It can be done through form layout window. Steps are:
Move the cursor to form layout window.
Drag the form to the position in which the form has to appear when it starts up.

THE PROPERTIES WINDOW


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.

The title bar of the Properties window says working with the properties of Form1.
The line below the title bar also tells what object we are working with; in this case it reads "Forml Form".
The highlighted line that reads "Caption" in the first column and "Form1" in the second column
The second column of the Properties window always indicates the current setting of the property.
The Settings box mostly works like an ordinary Windows text box as far as how you enter or edit
information
There's another method for changing the setting for a property, which some people prefer:
1. Move the mouse until the mouse pointer is in the right column of the correct line in the Properties
window.
2. Click at the location where you want to insert the text.
3. Enter the text you want to insert.
Finally, the default arrangement in the Properties window is alphabetical.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 19
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Moving through the properties window:


Use arrow keys or mouse to scroll through the property window.

An example of setting Non-Trivial Property:


By dragging the scrollbar the user can select the particular property or the shortcut key can be used to
select directly the property.
EX: MAX button option can be selected by scrolling or by using short cut key shift+ ctrl+ M

To run VB application:
Select start option from toolbar
Select start option from run menu or by pressing ALT +R,S
Press F5

To stop the VB application:


Click Exit button
Select End option in run menu
Use end tool in tool bar
Alt + F4

Key board shortcuts for manipulating the properties window


Key Action

SHIFT+CTRL+Letterkey Moves to the first item beginning with that letter


Down arrow Moves to the next item in the properties window
UP Arrow Moves to the previous item in the properties list box
Page Down / END Moves to the last item displayed in the properties list
box or to the last item
Page UP / HOME Moves to the first item displayed in the properties list box or
to the first item
F4 Brings up the properties window

COMMON FORM PROPERTIES:


Name:
It is the name by which the form is referred to in your code. Visual Basic gives default names to form
is Form1, Form2, Form3 etc. We should give the meaningful name to the form. For example in the main form
of the Inventory control project we should give the form name is frmMain. The name of a form cannot be
changed at runtime.
Caption:
The caption property appears on the title bar of the form. The caption can be changed at run time.
Picture:
The name of the file that contains the picture to be displayed on the form. This can be set at design
time and also in run time.
Background Color:
This property determines the background color of the form. In order to change the settings of this
property, double click value on the right color palettes will pop-up. Select the color of your choice.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 20
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

The Control Box:


The value for this is True or False. If it is set to True, the control box is visible on the top-left corner
of the form. If it set to false, it is not visible.
Min Button and Max Button:
The value for each of these properties is True or False. Set this to False. If you do not want the user to
minimize or maximize the form during run time.
Movable:
The default value is True. If set to false this form can not be moved by the user during run time. This
property is set to False when you do not want the user to move the form around the screen.
Border Style:
This property determines the type of window that the user will see during run time. You can allow
user to resize the form window or allow him to move the form window around.
Sets the border style of the form
0-none(no tile bar,max button,min button,close button)
1-fixed single(only close button)
2- sizable window (default)
3-fixed dialog (used for dialog box)
4-fixed tool window
5- sizable tool window
Font Properties:
Font properties for a form include the following:
Font Name: Name of the Font.
Font Style: If you select this, the text will be displayed in bold or italic or underlined.
Font Size: Size of the fonts in points
Position Properties:
Properties like Left, Top, Height and Width can be set at design time as well as runtime to locate the
form at a place of your choice.
Startup:
This property at design time will specify the position of the form at run time.
Enabled:
Appearance:
It determines whether the form has 3D look or not. Default value is 1 stands for 3 D appearance ,0 for flat
appearance.

Border style:
Visible:
To view the form in run time we use visible property.
Window state refers appearance of form in run time.
1- Reduces form to icon
2- Maximize the form
0- Normal (default)

SCALE PROPERTIES:
To place the object & control accurately inside the form this property is used.
 Scale mode: it change units used in form‘s internal coordinate system
 It uses one pixel as the scale.
Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 21
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

 Scale height, scale width: it is used to change the height and width of the form
 Scaleleft, scaletop: It is used to set the distance between the form and the window in left and top
while executing. It is useful when working with graphics.

The user may change the Forecolor, Backcolor in VB. The format used to store the color details is the
hexadecimal format. The user may change the Backcolor and Forecolor properties via color palette.

COLOR PROPERTIES.
The color value is stored in hexadecimal format and it allow maximum of 16,777,216 different colors. The
user may click color and select color from either system or palette option. The user may even define our own
color and this could be done through define color. Here the user may set the hue and saturation values and
according to that the values may change.

Working with Color Palette:


Now Goto View -> Color palette
Now click any one of the blank boxes and define colors option will be enabled and we can view the
following window.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 22
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

We can also create our own color palette. Each of the blank boxes on the bottom of the color palette
represents a possible custom color. To make one, follow these steps,
1. Click one of these blank boxes, and then click the Define Colors command (which is now
enabled). This opens the Define Color dialog box

2. Change the amount of red, green, or blue; color; hue; saturation; or luminosity of the color to suit
your needs by adjusting the controls in the dialog box.
3. Press the Add Color button to create the custom color or the Close button to cancel.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 23
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

UNIT – II
Building the User Interface: Toolbox – Creating Controls – Name Property - Properties of Command Buttons
- Image Controls - Text Boxes – Labels – Message Boxes – Grid. Anatomy of a VB Application – The Code
Window – Statement in Visual Basic – Variables – Data types – Working with Variables – Constants – Input-
Boxes

BUILDING THE USER INTERFACE:


Tool Box:
A toolbox contains number of controls. These controls are used to create a simple application. It
contains 21 controls. They are

 Text Box :Text box control is a versatile control. It can be used for getting the input from the
user and also display the result. It is called as Edit field or Edit control.

 Picture Box : It can display a graphic from a bitmap, icon or metafile as well as enhanced
metafile, JPEG or GIF files.

 Label Box : It allows you to display text that you don't want the user to change, such as
caption under a graphics.
 Option Button : It allows you to display the multiple choices from which the user can choose
only one option.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 24
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

 Frame Control : The frame control allows you to create graphical or functional grouping
controls.
 To group controls, draw the frame first and then draw controls inside the frame.
 List Box : List box displays a list of items. It can occupy some space on the form.
 Combo Box : Combo box is also used to display the items. But it can display a single item at a
time. It can occupy a less space on the screen.

 Data Control : Data control provides access to database through controls on your form.
 H Scroll Bar (Horizontal Scroll Bar) : Provides a graphical tool for quickly navigating
through a long list of items or a large amount of information for indicating the current position on a
scale, or as an input device or indicator of speed or quantity.

 V Scroll Bar (Vertical Scroll Bar) : Provides a graphical tool for quickly navigating through a
long list of items or a large amount of information for indicating the current position on a scale, or as
an input device or indicator of speed or quantity.
 Command Button : Creates a button that the user can choose to carry out a command. The user
will click on this button and the computer will perform the task associated with the button.
 Check Box : It allows you to display the multiple choices from which the user can choose any
number of items.
 Drive List Box, Directory List Box & File List Box : These controls are used to
display available Drives, Directories and Files. The user can select a valid Drive on his system. The
user can see a hierarchical structure of directories and files.
 Line control and Shape control : These controls are used to draw lines, square, circles,
rectangles and etc.
 Image control : It is very similar to the picture box control. Stretch property is available in
Image control. So we can easily resize the images.

 OLE (Object Linking & Embedding) : This control allows you to link your program to
another object or program like as Ms Word, Internet Explorer, and Ms Word etc.

 Timer control : It is a very important control. It is used for time-related processing. It is mainly
used in the auto save option.

CREATING CONTROLS:
We can get the control on a form by double clicking on its icon in the toolbox. This gives the default size and
shape in the middle of the form.
We can use combination of pointing, clicking, and dragging to manipulate the toolbox.
For example, to draw an item from the toolbox on a form at a specific location with a specific size:
 Move the mouse pointer to the tool that the user wants to use and click
 Move the mouse pointer to the form and draw the control
 Hold the mouse button down and drag the mouse to create the object

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 25
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

 Use eight little boxes called sizing handles to resize the control
 Locating controls only at grid points is called the aligning to the grid or snapping to the grid

Working with a control already on a form


User can also cut and paste controls using edit menu when they paste it appears on the top left hand corner of
the form
Resizing existing control:
 Use the properties window to adjust the width and height properties or
 Work with the sizing handles

Sizing handles

Simply click inside the control by moving the mouse pointer to the control and clicking once.
When the sizing handles are visible, know the control is selected.
The four corner handles let you change the height and width at the same time.
The mouse pointer changes to a double-sided diagonal arrow when you move the pointer to one of the corner
sizing handles.
The four side handles let you change the size in one direction only. At these handles, the mouse pointer
changes to a straight double-sided arrow.
Try resizing a control with the sizing handles by following these steps:
1. Move the mouse pointer to a sizing handle and click and hold down the left mouse button.
2. Drag the mouse until the control is the size you want.
Moving an existing control:
To move an existing control with the mouse, the focus must be at that control. To move an existing control:
 Move the pointer anywhere inside the control, click the left mouse button and hold it down.
 Drag the mouse until the control is at the location we want it to be and then release the left button.
For finer control movement select the control:
1. Select the control
2. Use ctrl + arrow key to move the control one grid mark at a time
3. Or, adjust the left and top properties in properties window.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 26
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Using double click shortcut for creating controls


Double click on any of the toolbox icons, matching control appers in the center of the screen

To create an application with three command buttons double click on the command button icons three times
Click on the tool it will create command buttons in the center of the screen.

Working with Multiple controls:


 Select each control by moving the mouse pointer to it and holding down the left mouse button while
pressing CTRL.
 Move the mouse pointer to any place outside the selected controls and click.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 27
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

The alignment used for a group of controls is determined by the control in the group with the black sizing
handles and this is the last control selected in the group.
Choose Format->Align->Left all the controls will move to match up with the command2 control.

Locking controls:
Lock the controls by unnecessarily moving properly positioned controls.
 Format->Lock Controls or
 Lock Control tool from the toolbar

Deleting Controls:
To delete a control:
 Move the mouse pointer until it is inside the control, and click the left mouse button to select it.
 Press DEL or Open Edit menu->Choose Delete option by pressing ALT+ E,D.

THE NAME (CONTROL NAME) PROPERTY


This property determines the name VB uses for the event procedures the user write to make the control
respond to the user.
To change the height of the current form type
Height=5000 or
Me.Height=5000 or
Default command button whose name property is MyCommandButton,
MyCommandButton.height=5000
All the above represents the same current working form.
If the user change the name of the form as Student then
Student.height=5000
Microsoft suggests using a prefix to start the name of any control. For command button the prefix is cmd.
Eg: if a command button is placed to move left, then it leads to a procedure like this:
Private sub cmdLeft_Click ()

End Sub
Rules for control name:
 Must begin with a letter
 After that, use any combination of letters, digits, and underscores.
 Name cannot be longer than 40 characters.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 28
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

PROPERTIES OF COMMAND BUTTONS


Command Button properties
By using the properties window we can customize the size and shape of the blank forms.
The Caption property: The Caption Property of a form determines the name that shows in the title bar.
Caption property on a command button determines what the user sees on the face of the button.
Any text you use for the caption on a command button is automatically centered within the button.

To change the name of the command button:


1. Move to the Properties window.
2. Go to the Caption property by using the mouse or the UP ARROW and DOWN ARROW keys.
Important properties of the command button are:

PROPERTY DESCRIPTION
Name The name of the object so you can call it at runtime
This specifies the command button's background color. Click the BackColor's
BackColor palette down arrow to see a list of common Windows control colours, you must
change this to the style property from 0 - standard to 1 - graphical
Determines whether the command button gets a Click event if the user presses
Cancel
escape
Caption Holds the text that appears on the command button.
Determins if the command button responds to an enter keypress even if another
Default
control has the focus

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 29
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Determines whether the command button is active. Often, you'll change the
Enable
enable property at runtime with code to prevent the user pressing the button
Produces a Font dialog box in which you can set the caption's font name , style
Font
and size.
Height Positions the height of the object - can be used for down
Left Positions the left control - can be used for right
If selected to an icon can change the picture of the mouse pointer over that
MousePointer
object
Hold's the name of an icon graphic image so that it appears as a picture instead
Picture
of a Button for this option to work the graphical tag must be set to 1
This determines if the Command Button appears as a standard windows dialog
Style
box or a graphical image
Tab index Specifies the order of the command button in tab order
Whether the object can be tabbed to ( this can be used in labels which have no
Tab Stop
other function )
If the mouse is held over the object a brief description can be displayed (for
Tool Tip Text
example hold your mouse over one of the above pictures to see this happening
Visible If you want the user to see the button/label select true other wise just press false
Width Show the width of the object

SIMPLE EVENT PROCEDURES FOR COMMAND BUTTONS


Every command button will have an event procedure. The procedure is executed when the button is clicked.
To write the procedure,
1. Double click a control or press F7 to go to code window
2. Select the required event for the command button and write the procedure for it.
For example the command button shown below has the name property as CmdClickMe and the code written
for it is (Print ―SSM College‖) and the event is Click.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 30
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 31
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

THE IMAGE CONTROL


Image controls hold pictures.
They can also be used for creating toolboxes
Image controls can be used to display icons or pictures created with the program such as Microsoft
paintbrush. They can also hold windows metafiles, JREGs or Gif files.

Image controls are windowless objects that are managed by Visual Basic without creating a Windows object.
Image controls can load bitmaps and JPEG and GIF images.
It is used to display a graphic. An Image control can display a graphic from a bitmap, Icon, or metafile, as
well as enhanced metafile, JPEG, or GIF files.
PROPERTY DESCRIPTION DATA VALUE
Left, Top This property determines the distance
between the Image Control and the left
edge and top of the container (form),
respectively.
BorderStyle Returns/sets the border style of the object  No border (setting =0)
 (Default) Fixed Single border
(Setting=1)
Stretch Returns or sets a value indicating whether  True-The graphic resizes to fit
a graphic resizes to fit the size of an Image the control.
control  False-(Default) The control
resizes to fit the graphic.
Picture Returns or sets a graphic to be displayed in Picture(Bitmap, metafile, Icon
a control. etc)
The most important property of a image control is Stretch property. It determines whether the image control
adjusts to fits the picture, the picture adjust to fit the control.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 32
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

TEXTBOXES
Textbox is the primary methods of getting input and displaying the output in VB.
A text box object is used to display text on a form or to get user input while a VB is running
In a text box, a user can type data or paste it into the control from the clipboard.
The textbox never treat the user input as number and this means getting numeric input to VB program
requires transforming a string of digits into number by using built in function or automatic type
conversion

The following table summarizes the common TextBox control's properties and methods.
Property/ Method Description
Enabled specifies whether user can interact with this control or not
Index Specifies the control array index
Locked If this control is set to True user can use it else if this control is set to
false the control cannot be used
MaxLength Specifies the maximum number of characters to be input. Default
value is set to 0 that means user can input any number of characters
MousePointer Using this we can set the shape of the mouse pointer when over a
TextBox
Multiline By setting this property to True user can have more than one line in
the TextBox

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 33
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

PasswordChar This is to specify mask character to be displayed in the TextBox


ScrollBars This to set either the vertical scrollbars or horizontal scrollbars to
make appear in the TextBox. User can also set it to both vertical and
horizontal. This property is used with the Multiline property.
Text Specifies the text to be displayed in the TextBox at runtime
ToolTipIndex This is used to display what text is displayed or in the control
Visible By setting this user can make the Textbox control visible or invisible
at runtime

Method
SetFocus Transfers focus to the TextBox

Event procedures
Change Action happens when the TextBox changes
Click Action happens when the TextBox is clicked
GotFocus Action happens when the TextBox receives the active focus
LostFocus Action happens when the TextBox loses it focus
KeyDown Called when a key is pressed while the TextBox has the focus
KeyUp Called when a key is released while the TextBox has the focus

LABELS:
It is used to display static text, titles and screen output from operations.
It is used to identify a textbox or other control by describing its content.

Properties for Labels


1. Caption Property: To display text on a label control, set its Caption property.
2. BackColor Property: Sets the back color of the label
3. ForeColor Property: Sets the fore color (color of the text that is displayed) of the label
4. Visible Property: Makes the labels appear and disappear by setting the value true or false.
5. Alignment: Return/sets the alignment of a control‘s text. By setting the values as
 0-(default) left-aligned

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 34
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

 1-right-aligned
 2-center
6. BorderStyle: Returns/sets the border style of the object. By setting the values as
 No border (setting =0)
 (Default) Fixed Single border (setting =1)
7. BackStyle: Determines whether the label is transparent or opaque.
8. Autosize: Determines whether a control is automatically resized to display its entire contents. By setting
the values as
 True- resized according to the contents
 False (default)-does not resizes.
9. WordWrap: Returns/sets a value that determines whether a control expands to fit the text in its caption.
By setting the values as
 True- wraps the contents
 False (default)-does not wraps the contents.
10. Multiline- True or False - if True, you can have several lines of text, by default, it is set to False

Some Event Procedures for Labels


 Click event- it occurs on clicking the label.
 Change event- it occurs when the contents of a control have changed.
 DblClick event- it occurs on double clicking the label.
 MouseDown-it occurs when the user presses the mouse button.
 MouseUp events-it occurs when the user releases the mouse button.
 MouseMove event-it occurs when the mouse is moved towards the label.

MESSAGE BOX
The message box displays a message in a dialog box, waits for the user to click a button, and returns an
integer indicating which button the user clicked.

Syntax:
Msgbox(Prompt,[buttons],[title])

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 35
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Prompt-String expression displayed as the message in the dialog box.


Buttons-Numeric Expression that is the sum of values specifying the number and type of buttons to display,
the icon style to use, the identity of the default button, and the modality of the message box. If omitted, the
default value for buttons is 0.
Title- String Expression displayed in the title bar of the dialog box. If omitted, the application name is placed
in the title bar.

The button argument settings are:


Constant Values Description
VbOkOnly 0 Display ok button only
VbOkCancel 1 Display Ok and Cancel buttons
VbAbortRetryCancel 2 Display Abort, Retry, Cancel
VbYesNoCancel 3 Display Yes, No, Cancel
VbYesNo 4 Display Yes, No
VbRetryCancel 5 Display Retry, Cancel
VbCritical 16 Display critical message icon
VbQuestion 32 Display Warning query icon
VbExclamation 48 Display Warning message icon
VbInformation 64 Display Information message icon.
VbDefaultButton1 0 First Button is default
VbDefaultButton2 256 Second Button is default
VbDefaultButton3 512 Third Button is default
VbDefaultButton4 768 Fourth Button is default
The first group of values (0-5) describes the number and type of buttons displayed in the dialog box; the
second group(16,32,48,64) describes the icon style; the third group(0,256,512,768) determines which button
is default. When adding numbers to create a final value will be returned.
For Example:
Private Sub Command1_Click ()
Dim Result as Integer
Result =Msgbox (―Hello‖, VbOkCancel+VbCritical+VbDefaultButton1,‖Sample‖)
End Sub

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 36
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

THE GRID:
Grid is important for accurately positioning controls. In order to control the grid, choose Tools|Options
(ALT+T, O), and then go to the General page on the options dialog box, as shown in the figure.

The properties we can control are described next.


Show Grid –We can turn the grid on or off by changing the Show Grid setting. The default setting is on.
Grid Width, Grid Height Boxes- The width and Height text boxes allows setting the distance (in twips)
between grid marks. The default is 120 twips.
Align Controls to Grid- This check box determines whether controls automatically move to the next grid
mark or whether they can be placed between grid marks.

ANATOMY OF THE CODE WINDOW:


The title bar of the code window contains the name of the Project and Form name.
Next there are two combo boxes. One holds the text ―Form‖ and the other holds the text ―Load‖.

This means that form is the name of the object and load is the event that you want to write the code for.
Click the down arrow button and the Drop Down list box will display all the controls that have been placed in
the form.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 37
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

If you intend to write the Command1, then select it from the list by clicking on it. Now click on the Down
arrow button on the other Drop down control. This will list all the events related to the selected object. The
lines given below provide a framework within which you can enter the code.
Private Sub Command1_Click ()

End Sub
The Private means that the variables declared and the code used here can be used only by this function. Then
we have the word Sub. This is short for Sub-routine or Function. Command1_Click() is the name of the
function which is self explanatory. End Sub means end of this subroutine.

Working with the Form-Click Event

 Move to the event drop-down list box on the right and click the down arrow.
 Move through the box until the user get to the click item.
 Select Form_Click event and click on it.
Then Visual Basic does the following:
 Gives the user a new event procedure template for the Form-Click event procedure
 Adds a dotted line between the Form_Load event and the click event.
 Moves the cursor to the blank line before the End Sub line in the click event procedure.
Output
When the user run the form and click once above the form it will show the following output

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 38
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

STATEMENTS IN VISUAL BASIC:


A statement in a programming language is a complete sentence.
Visual basic ignores case and spacing, except within quotes.
Statements generally occurs in own lines. Lines are limited to 1,023 characters but a statement can be
extended to next line by using the underscore character ( _ ) preceded by a space at the end of the
line.
Comment Statements:
These statements are statements that help to explain our code to people, but they are not processed by visual
Basic. They are also known remark statements.
There are two ways to indicate a comment statement.
 Using single quotation mark (‗)
 Using Rem keyword
For eg:
1. Private sub command1_click()
‗This is an example of comment statement using single quotes
End Sub
2. Private sub command1_click()
Rem This is an example of comment statement using Rem
End Sub

The End statement:


When VB processes an End Statement, the program stops (i.e.). The program, which is presently running, gets
closed and cleared from memory.
There are ways to indicate an End statement
 Using End keyword
 Using Unload Me keyword
For e.g.
1.Private sub command1_click()
End
End Sub
2.Private sub command1_click()
Unload Me
End Sub

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 39
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

VARIABLES
In Visual Basic, Variables are used to store values temporarily during the execution of an application.
Variables have a name (the word use to refer to the value the variable contains) and a data type (which
determines the kind of data the variable can store). Variable is a placeholder in memory for an unknown value

Declaring Variables
To declare a variable is to tell the program about it in advance. Declare a variable with the Dim statement,
supplying a name for the variable:
Dim variablename [As type]
Variables declared with the Dim statement within a procedure exist only as long as the procedure is
executing. When the procedure finishes, the value of the variable disappears. In addition, the value of a
variable in a procedure is local to that procedure — that is, we can't access a variable in one procedure from
another procedure. A naming convention of a variable:
Must begin with a letter.
Can't contain an embedded period or embedded type-declaration character.
Must not exceed 255 characters.
Must be unique within the same scope, which is the range from which the variable can be referenced
— a procedure, a form, and so on.
The optional As type clause in the Dim statement allows us to define the data type or object type of the
variable that we are declaring. Data types define the type of information the variable stores. Some examples
of data types include String, Integer, and Currency
There are other ways to declare variables:
Declaring a variable using the Public keyword makes it available throughout our application.
Declaring a local variable using the Static keyword preserves its value even when a procedure ends.

Implicit Declaration:
In VB, don't have to declare a variable before using it. For example, we can write a function where we don't
need to declare TempVal before using it:
Function SafeSqr(num)
TempVal = Abs(num)
SafeSqr = Sqr(TempVal)
End Function
Visual Basic automatically creates a variable with that name, which we can use as if we have explicitly
declared it. While this is convenient, it can lead to subtle errors in our code if we misspell a variable name.
For example, suppose that this was the function we wrote:

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 40
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Function SafeSqr(num)
TempVal = Abs(num)
SafeSqr = Sqr(TemVal)
End Function
At first glance, this looks the same. But because the TempVal variable was misspelled on the next-to-last line,
this function will always return zero. When Visual Basic encounters a new name, it can't determine whether
we actually meant to implicitly declare a new variable or we just misspelled an existing variable name, so it
creates a new variable with that name.

Explicit Declaration
To avoid the problem of misnaming variables, we can stipulate that Visual Basic always warn us whenever it
encounters a name not declared explicitly as a variable.
To explicitly declare variables
Place this statement in the Declarations section of a class, form, or standard module:
Option Explicit
–or–
From the Tools menu, choose Options, click the Editor tab and check the Require Variable Declaration
option.
This automatically inserts the Option Explicit statement in any new modules, but not in modules already
created; therefore, we must manually add Option Explicit to any existing modules within a project.

Data Types
Variant: By default Visual Basic variables are of variant data types. The variant data type can store numeric,
date/time or string data. We can also declare explicitly a variable as variant. When a variable is declared, a
data type is supplied for it that determines the kind of data they can store .The fundamental data types in
visual basic including variant are integer, long, single, double, string, currency.

String: It is used to hold characters. It can be single character or many. A variable holding a string is called a
string variable. One method of identifying variables of this type is to place a dollar sign ($) at the end of the
variable name: a$=‘ABC‘

Integer: It is used to hold relatively small integer values (between –32,768 and +32,767). One method of
identifying variables of this type is to place a percent sign (%) at the end of the variable name: a$=3

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 41
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Long Integer: It is used to hold integer values (between –2,147,483,648 and 2,147,483,648). One method of
identifying variables of this type is to place a ampersand sign (&) at the end of the variable name:
a&=123456789

Single Precision: Just as there are two integer types for different size values, numbers with decimal points
have different variable types depending on how large and how accurate we want them to be. The least
accurate is called single precision. They have a decimal point, but of seven digits accuracy .It is used to hold
decimal values. One method of identifying variables of this type is to place a exclamation sign (!) at the end
of the variable name: a!=12.345

Double Precision: The double-precision data type is used when we need numbers with up to 16 places of
accuracy. These variables are mainly used in scientific calculations in Visual Basic. One method of
identifying variables of this type is to place a pound sign (#) at the end of the variable name: a#=12.345

Currency: This type can have 4 digits to the right of the decimal place and up to 15 to the left of the decimal
point. Arithmetic will be exact within this range. One method of identifying variables of this type is to place a
‗at‘ (@) at the end of the variable name: a@=12.345

Date: This type gives a convenient way to store both date and time information for any time between
midnight on January 1,100, to midnight on December 31, 9999. We need to surround any assignment to date
variables with two #‘s, for example: Millennium= #January 1,2000#

Byte: It is used to hold between 0 and 255.This is a great convenience when we need to save space , and it
makes certain arrays much smaller .

Boolean: It is used to hold data either true or false .It is considered good programming practice to use this
data type rather than integers for True/False values.

WORKING WITH VARIABLES:


Scope and Lifetime of Variables
1. Local scope: The value of the variable can be accessed only within a event procedure where it is
declared.
2. Global scope: The value of the variable can be accessed by all the procedures present in the form
module.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 42
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

3. Static: Variables have a lifetime in addition to scope. The values in module-level and public variables
are preserved for lifetime of an application whereas local variables declared with Dim, exist only
while the procedure in which they are declared is executing. The value of a local variable can be
preserved using Static keyword.

More on Strings
A String is simply a bunch of characters surrounded by double quotes.
String Concatenation
Concatenation of two Strings can be done using ampersand (&).For example:
Name1$=‖Visual‖
Name2$=‖Basic‖
Subject_name$=Name1 & Name2
MsgBox Subject_name
Output will be Visual Basic displayed using message box.
Fixed-Length Strings
A fixed-length string is a special type of string that plays an important role.These variables are created using
Dim statement .Here is an example:
Dim shortstring As String * 10
Dim strshort As String * 10
Both of these statements set up string variables However, this variable will always hold strings of length 10.If
we assign a longer string to shortstring ,as shown below
shortstring=‖antidisestablishment‖
We will get is the same thing as:
Shortstring=‖antidisest‖As we can also see, the variable contains only the left ten characters of the value.
Similarly, if we assign a shorter string to shortstring, like this,
Shortstring=‖a‖
We still get a string of length 10,only this time the contents of the variable are padded on the right so that the
string is really stored in the same way as:
Shortstring=‖a‖
Thus, fixed-strings are ―right padded‖ if necessary.

More on Numbers

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 43
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

We can use a decimal point, but if we assign such a number to an integer or long Integer variable, it will
automatically be rounded to an integer value. If we assign a number larger than the limits for the given
variable ,Visual Basic will give the user an error message at run time.
Here are some examples:
Number Acceptable in an assignment to a nume
variable?
3001 Okay for all number variables
3000001 Okay for all but short Integer variables
30000.01 Okay for all but integer variables (rounded
for them and for long integer variables)
3,001 Illegal because it uses a comma

The Numeric Operators


Operator Operation
+ Addition
- Subtraction (and used to denote negat
numbers)
/ Division
* Multiplication
^ Exponentiation
\ Integer division(this symbol is a backslash)
Mod The remainder after Integer division

Hierarchy of Operations:
The following list gives the order of operations:
Exponentiation
Negation (Making a number negative)
Division and Multiplication
Integer division
The remainder (Mod) function
Addition and Subtraction

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 44
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

CONSTANTS
Constants, like variables, are named storage locations in memory with local, form, module, or global scope.
Visual Basic prevents the value of a constant from being changed during program execution. It uses constants
more efficiently than variables, so if we plan to use a value that never changes, we should create a constant.
To create a constant, we use the Const statement with the following syntax:
For example: Const A =10
A naming convention of a constant:
Must begin with a letter.
Can't contain an embedded period or embedded type-declaration character.
Must not exceed 255 characters.

INPUT BOXES
Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns a String
containing the contents of the text box.
Following is an expanded InputBox

Syntax :
variablename = InputBox (prompt[,title][,default][,xpos][,ypos][,helpfile,context])
variablename is a variant data type but typically it is declared as string, which accept the message input by the
users.
The arguments are explained as follows:
Prompt - String expression displayed as the message in the dialog box. If prompt consists of more
than one line, the user can separate the lines using the vbCrLf constant
Title - String expression displayed in the title bar of the dialog box. If the user omit the title, the
application name is displayed in the title bar
default-text - The default text that appears in the input field where users can use it as his intended
input or he may change to the message he wish to key in.
x-position and y-position - the position or the coordinate of the input box.
The twp paratmeters helpfile and context are used together when the user have a help message
attached to the box.
Following example demonstrates the use of InputBox function

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 45
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

* Open a new project and save the Form as InputBox.frm and save the Project as InputBox.vbp
* Design the application as shown below.

Object Property Setting

Form Caption InputBox test


Name frmInputBox
Label Caption The user entered
Name lbl1

Caption ( empty)
Label
Name lbl2
BorderStyle 1-Fixed Single
CommandButton Caption OK
Name cmdOK

Following code is entered in cmdOK_Click ( ) event


Private Sub cmdok_Click()
Dim ans As String
ans = InputBox("Enter something to be displayed in the label", "Testing", 0)
If ans = "" Then
lbl2.Caption = "No message"
Else
lbl2.Caption = ans
End If
End Sub
Save and run the application. As soon as the user click the OK button the user will get the following InputBox

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 46
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Here I have entered "Hello World" in text field. As soon as the user click OK the output is shown as shown
below

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 47
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

UNIT- III
Display Information on a Form - The Format Function - Picture Boxes – Rich Text Boxes – The Printer
Object - Determinate Loops - Indeterminate Loops – Making Decisions – Select Cases – Nested If- Then –
The GOTO – String Functions – Numeric Functions – Date and Time functions – Financial Functions

DISPLAY INFORMATION ON A FORM


 Visual basic displays text on a form using the Print method. The general syntax for Print method is
FormName.Print expression
where expression is any Visual Basic expression that VB can convert to a string.
 Visual Basic uses whatever settings are current for the Font object for the current form in order to
determine the loot information to use when it prints.
CurrentX and CurrentY
 In many fonts, letters like "m" take up more space than letters like "i".
 Fonts in which all characters are the same width are called non-proportionally spaced fonts;
 Ex: Font name: Courier New
This is net in Courier New.
 Fonts where characters may be of different widths are called proportionally spaced fonts.
Ex: Font name: Arial
This is set in Arial.
 CurrentX refers to the horizontal position where visual basic will display the information
 CurrentY refers to the vertical position where it displays the information.
 To set the CurrentX and CurrentY property
FormName. CurrentX= Value
FormName. CurrentY= Value
 The value may me any numeric expression from which VB can extract a single-precision.

THE FORMAT FUNCTION


Numeric Formatting
 The format function is used to format dates, numbers and strings with ease. We can choose from Format‘s
predefined named formats, such as Currency or Fixed, or insist on finer control by creating our own user-
defined format.
 The Format function returns a string, which we can use for either screen or printer output.
Syntax:
Format(Expression[,format[,Firstday of week])
Numeric formatting has various format values. The values are given below
Format Name Description
General Number
Displays the number without and
E.g. Me.Print.Format (1234,‖General number‖)
thousands operator
Gives the result 1234
Currency Displays the number depending on the
E.g. Me.Print.Format (1234,‖Currency‖) settings for currency configured in the
Gives the result $1,234.00 control panel

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 48
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Fixed
Displays a minimum of one digit to the left
E.g. Me.Print.Format (1234,‖Fixed‖)
and two to the right of the decimal point.
Gives the result 1234.00
Standard
E.g. Me.Print.Format (1234,‖Standard‖) The same as fixed, except that the number
Gives the result 1,234.00 is also formatted with thousands separators.

Percent Displays the number as percentage by


E.g. Me.Print.Format (0.01234,‖Percent‖) multiplying it by 100 first. The number is
Gives the result 1.23% always displayed with two digits to the
right of the decimal point and with the
trailing percent sign
Scientific
E.g. Me.Print.Format (0.01234,‖Scientific‖) Uses Standard scientific notation
Gives the result 1.23E-02
Yes/No
Displays No if the number is zero;
E.g. Me.Print.Format (False, ‖Yes/No‖)
Otherwise displays Yes.
Gives the result No
True/False
Displays False if the number is zero;
E.g. Me.Print.Format (50, ‖True/False‖)
Otherwise displays True.
Gives the result True
On/Off
Displays Off if the number is zero;
E.g. Me.Print.Format (True, ‖On/Off‖)
Otherwise displays On.
Gives the result On

Date Formatting:
Date Formats has various values, they are given below
Format Name Description
General Date This is the most flexible date/time format. If the date
E.g. Me.Print.Format(Now,‖General Date‖) expression passed has only an integer portion, only the
Give result 12-10-99 9:14:25 PM date is displayed. Similarly, if it has only a decimal
portion, only the time is displayed
Long Date
This format will display a date in the format specified
E.g. Me.Print.Format(Now,‖Long Date‖)
by our system long date setting
Give result Thursday,December 10,1999
Medium Date
This format will display a date in the format specified
E.g. Me.Print.Format(Now,‖Medium Date‖)
by our system medium date setting
Give result 10-Dec-99
Short Date
This format will display a date in the format specified
E.g. Me.Print.Format(Now,‖Short Date‖)
by our system short date setting
Give result 12-10-99
Long Time
This format will display a date in the format specified
E.g. Me.Print.Format(Now,‖Long Time‖)
by our system long time setting
Give result 9:14:25 PM

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 49
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Medium Date
This format will display a date in the format specified
E.g. Me.Print.Format(Now,‖Medium Time‖)
by our system medium time setting
Give result 09:14 PM
Short Date
This format will display a date in the format specified
E.g. Me.Print.Format(Now,‖Short Time‖)
by our system short time setting
Give result 21:14

PICTURE BOXES
Like image control, picture boxes display icons, gifs, jpegs, bitmaps, and windows metafiles.
The following points describe a PictureBox control:
The pictureBox control comes with a light border around it.
Works as a container: You can place any other control on it, when you move the PictureBox control, all
the controls on it moves along with. That means, it works as a container of other controls.
Similarity with the Form: This control is so similar to a form as both of them support all the graphical
properties, graphical methods and conversion methods.
Supports all the graphical properties: It supports all the graphical properties such as AutoRedraw,
ClipControls, HasDC, FontTransparent, CurrentX, CurrentY, and the Drawxxxx, Fillxxxx, and Scalexxxx
properties.
Supports all the graphical methods: It supports all the graphical methods such as Cls, PSet, Point, Line,
and Circle.
Supports the conversion methods: It supports the conversion methods such as ScaleX, ScaleY,
TextWidth, and TextHeight.
Loading images: Using the Picture property, you can load a picture in design time and run-time. The
LoadPicture function is used to load the picture from your computer. This function is used with both the
PictureBox and Image controls.

We can programmatically load any image in the control using the LoadPicture function:
Picture1.Picture = LoadPicture("c:\windows\setup.bmp")
We can copy an image from one PictureBox control to another by assigning the target control's Picture
property:
Picture2.Picture = Picture1.Picture

The main advantages to using a picture box rather than a form to display data are that
1. Information displayed in a picture box will not be obscured by any controls on the form
2. Picture boxes are less memory-hungry.
3. We can have more than one picture box on a single form.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 50
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

RICH TEXT BOXES


 The RichTextBox control allows the user to display, enter, and edit text while also providing more
advanced formatting features than the conventional TextBox control.
 The RichTextBox control opens and saves files in both the RTF format and regular ASCII text format.
 The RichTextBox control supports object embedding by using the OLEObjects collection.
 To print all or part of the text in a RichTextBox control use the SelPrint method.
 The RichTextBox control supports almost all of the properties, events and methods used with the
standard TextBox control, such as MaxLength, MultiLine, ScrollBars, SelLength, SelStart,
and SelText.
 The RichTextBox control must be added to the toolbox via the Components dialog box, as shown
below.

This dialog box is accessed via the Project menu, Components item.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 51
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Once you check "Microsoft Rich Textbox Control 6.0" and click OK, the control is added to your toolbox
(also shown below, circled).
Then you can double-click it to make it appear on your form, as you would with any other control.

Properties of the RichTextBox Control:


Property Description
DisableNoScroll Returns or sets a Boolean value that determines whether scroll bars in the
RichTextBox control are disabled.
FileName Returns or sets the filename of the file loaded into the RichTextBox control. Only
the names of text files or valid .rtf files can be specified for this property.
Locked Returns or sets a Boolean value indicating whether the contents of the RTB can be
edited.
MaxLength Returns or sets a value (Long) indicating whether there is a maximum number of
characters a RichTextBox control can hold and, if so, specifies the maximum
number of characters.
MultiLine Returns or sets a Boolean value indicating whether the RTB can accept and display
multiple lines of text. A multiple-line RichTextBox control wraps text as the user
types text extending beyond the text box. Scroll bars can be added to to a larger
RichTextBox control using the ScrollBars property.
OLEObjects Every embedded OLE object created in the RichTextBox control is represented in
the OLEObjects collection.
RightMargin The RightMargin property is a Long value used to set the right most limit for text
wrapping, centering, and indentation.
ScrollBars Returns or sets a value indicating whether the RTB has horizontal or vertical scroll
bars. Read-only at run-time. Possible values are 0-rtfNone (default, no scroll bars
shown), 1-rtfHorizontal (horizontal scroll bar only), 2-rtfVertical (vertical scroll
bar only), or 3-rtfBoth (both horizontal and vertical scroll bars shown).
For a RichTextBox control with setting 1 (Horizontal), 2 (Vertical), or 3 (Both),
you must set the MultiLine property to True.
SelAlignment Returns or sets a value that controls the alignment of the paragraphs in a
RichTextBox control.
SelBold, SelItalic, Boolean. Return or set font styles of the currently selected text in a RichTextBox
SelUnderline, control. The font styles include the following formats: Bold, Italic, Strikethru, and
SelStrikethru Underline.
SelColor Returns or sets a value that determines the color of text in the RichTextBox
control.
SelFontName Returns or sets the font used to display the currently selected text or the
character(s) immediately following the insertion point in the RichTextBox control.
SelFontSize Returns or sets a value that specifies the size of the font used to display text in a
RichTextBox control.
SelIndent, Returns or sets the margin settings for the paragraph(s) in a RichTextBox control
SelRightIndent, that either contain the current selection or are added at the current insertion point.
SelHangingIndent
SelProtected Returns or sets a value which determines if the current selection is protected.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 52
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

SelStart, SelLength,  SelLength — returns or sets the number of characters selected.


SelText  SelStart — returns or sets the starting point of text selected; indicates the
position of the insertion point if no text is selected.
 SelText — returns or sets the string containing the currently selected text;
consists of a zero-length string ("") if no characters are selected.
SelRTF Returns or sets the text (in .rtf format) in the current selection of a RichTextBox
control.
SelTabCount , Returns or sets the number of tabs and the absolute tab positions of text in
SelTabs a RichTextBoxcontrol. Not available at design time.
TextRTF Returns or sets the text of a RichTextBox control, including all .rtf code.

Methods of the RichTextBox Control:


Method Description
LoadFile Loads an .rtf file or text file into a RichTextBox control.
SaveFile Saves the contents of a RichTextBox control to a file.
Syntax:
RichTextBox1.SaveFile pathname, filetype
Where pathname is a string defining the path and filename of the file to
receive the contents of the control and filetype is an integer or constant that
specifies the type of file to be saved. Valid values for filetype are 0 (or the
constant rtfRTF; default, saves contents as a .rtf file), or 1
(constant rtfText, saves contents as a text file).
Find Searches the text in a RichTextBox control for a given string.
GetLineFromChar Returns the number of the line containing a specified character position in
a RichTextBoxcontrol.
Span Selects text in a RichTextBox control based on a set of specified
characters.
SelPrint Sends formatted text in a RichTextBox control to a device for printing.

THE PRINTER OBJECT


The user has only written programs that send output to the screen and not the printer. Now the user will learn
how to send an output to the printer and get it printed. Sending output to the printer is a simple task in Visual
Basic, it involves the use of the Printer object and the print method. The standard code of sending an output to
the printer and get it printed out is as follows:
Private Sub Form_Load()
Printer.Print "Welcome to Visual Basic"
End Sub
However, the code above only send the output to the printer without actually printing it. It will only print the
output when you terminate the application. It can a very inconvenience if you need to close the program
every time you want to print the output. To solve this little problem, we need to add the newpage or EndDoc
method. So, add one extra line to the above code as follows:
Private Sub Form_Load()
Printer.Print "Welcome to Visual Basic"
Printer.EndDoc
End Sub

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 53
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Useful properties and methods for the Printer


ColorMode: This property lets the user determine whether a color printer prints in color or monochrome. The
two possibilities are shown in the following table.
Symbolic Constant Value Description
vbPRCMonochrome 1 Prints output in monochrome
vbPRCMColor 2 Prints output in color
Color: This property lets the user set the number of copies to be printed.
Height,Width: These properties give the user the height and width of the paper in the printer as reported by
windows.
EndDoc : This method tells windows that a document is finished. The syntax is
Printer.EndDoc
NewPage : This method ends the current page and tells the printer to move to the next page. The syntax is
Priter.Newpage
Page: This property keeps track of the number of pages printed in the current document.
PrintQuality : This property is used to set the quality of the printed output, if the printer driver supports it.
The syntax is
Printer.PrintQuality = Value
Four built-in constants
vbPRPQDraft -1 Draft resolution
vbPRPQLow -2 LOW resolution
vbPRPQMedium -3 Medium resolution
vbPRPQHigh -4 High resolution

DETERMINATE LOOPS
Controlling Program Flow: The parts of a programming language that let to repeat operations or make
decisions are often called Control Structures
Loop: the code that repeats an operation. Two types of loops:
1. Determinate loop: Repeating an operation to a fixed number of times
1. for next loop
2. Nested for loop
2. Indeterminate loop: Indeterminate loops run for an unknown number of repetitions until a condition
is true or while a condition is true.
Four types of indeterminate loops
1. do while. .. loop
2. do. .. until loop
3. while. .. wend loop
4. Do. ... loop while
The For. Next Loop
The For. Next Loop is another way to make loops in Visual Basic.
It comes under the category of determinant loop which means number of times loop repeats is known.
Repeats a group of statements a specified number of times.

Syntax:
For counterVariable = fromValue To toValue step stepvalue
...VB Statements...

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 54
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Next counterVariable

countervariable-keeps count on the loop


fromvalue-start value of the for loop
tovalue-end value of the for loop
when the difference between first number and second number is > 1 then use step to provide the
difference.
default step value is 1
when you want decrement counter provide the step value in negative.
when you want increment counter provide the step value in positive.

Example:
The following loop counts the numbers from 1 to 100:
Dim x As Integer
For x = 1 To 50
Print x
Next

In order to count the numbers from 1 to 50 in steps of 2, the following loop can be used

For x = 1 To 50 Step 2
Print x
Next

The following loop counts numbers as 1, 3, 5, 7..etc . The above coding will display numbers vertically on the
form.

Nested for:
A loop can be coded within another loop thus forming nested loops.
There can be many levels of nesting.
nesting is possible as long as the inner structure is completely enclosed in the outer structure.
When nesting loops, each loop must have a unique counter variable.
For example, nested loops are needed to display a table of values, to process the elements of a two-
dimensional array, or to sort array elements using the Bubble Sort algorithm

Syntax:
for counter-variable1=start-value to end-value[step step-value]
statements......
for counter-variable2=start-value to end-value[step step-value]
statements......
next counter-variable2
next counter-variable1
Example:
To print the elements of an 2x2 array
for i=1 to 2

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 55
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

for j=1 to 2
print a(i,j),
next j
print
next i
Exiting a For..Next Loop
The Exit For Statement is used to exit directly from the For …Next loop
The Syntax is
For counter=Start To End [Step Increment/Decrement] \
[Statements]
If [Condition] then
Exit For
End If
Next [Counter]
Flow Diagram of For…Next loop

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 56
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

INDETERMINATE LOOPS:
Four types of indeterminate loops
1. do while. .. loop
2. do. .. until loop
3. while. .. wend loop
4. Do. ... loop while
1. do while. ... loop :
The Do While. Loop is used to execute statements until a certain condition is met.
Syntax:
Do While (Expression)
(Code to execute)
Loop
(Expression) can be any legal logical expression that we wish to evaluate to determine whether or not
to exit the loop.
Each time the program reaches Loop it will verify that this expression is True, and if it is False, it will
exit the loop.
Thus, instead of exiting when an expression is True, it now exits only once this expression is false.
Example:
The following Do Loop counts from 1 to 100.
Dim number As Integer
number = 1
Do While number <= 100
number = number + 1
Loop
A variable number is initialized to 1 and then the Do While Loop starts.
First, the condition is tested; if condition is True, then the statements are executed.
When it gets to the Loop it goes back to the Do and tests condition again.
If condition is False on the first pass, the statements are never executed.

2. do. .. until loop:


 Unlike the Do While...Loop and While...Wend repetition structures, the Do Until ... Loop structure tests a
condition for falsity.
 Statements in the body of a Do Until .. Loop are executed repeatedly as long as the loop-continuation test
evaluates to False.

Syntax:
Do Until (Expression)
(Code to execute)
Loop
 (Expression) can be any legal logical expression that we wish to evaluate to determine whether or not to
exit the loop.
 Each time the program reaches Loop it will evaluate this expression.
 If the expression is True, it will exit the loop , but otherwise it will continue looping.
Example for Do Until .. Loop statement:
The coding is typed inside the click event of the command button

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 57
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Dim number As Long


number=0
Do Until number > 1000
number = number + 1
Print number
Loop
Numbers between 1 to 1000 will be displayed on the form as soon as we click on the command button.

3. While ... wend loop


A While...Wend statement behaves like the Do While. Loop statement.
Repeats the loop until the test condition is true,else it comes out of the loop for false.
Syntax:
While (test condition)
code to execute
wend
Example:
The following While. Wend counts from 1 to 100
Dim number As Integer
number = 1
While number <=100
number = number + 1
Wend

4. Do. ... loop while


The most basic form of loop in Visual Basic is the Do-Loop.
Its construct is very simple:
This, quite simply, executes the block of code, and when it reaches Loop, returns to the beginning of
the Do Loop and executes the same block of code again.
The same block of code will be repeatedly executed until it is told to stop executing.
The Do...Loop While statement first executes the statements and then test the condition after each
execution.
Syntax:
Do
(Code to execute)
Loop while (test condition)
Example:
Dim number As Long
number = 0
Do
number = number + 1
Loop While number < 501
 The program executes the statements between Do and Loop While.
 Then it determines whether the counter is less than 501.
 If so, the program again executes the statements between Do and Loop While else exits the Loop.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 58
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

MAKING DECISIONS
Control Structures allow applications written in visual Basic to respond to different situations depending upon
the result of a test Conditions. The Condition can be comparison or any expression that evaluates to a numeric
value
The available conditional Structures are:
 If…Then Statements
 If…Then…Else Statements
 If….Then…ElseIf Statements
 Select Case Statements

1. If...Then Statement:
Description: The If...Then statement examines the truthfulness of an expression.
Syntax:
If ( expression ) Then
Statement
End If
 The program examines a condition. This expression can be a simple expression or a combination of
expressions.
 If the expression is true, then the program will execute the Statement.
 There are two ways we can use the If...Then statement.
 If the conditional formula is short enough, we can write it on one line, like this:
If expression Then Statement
 If there are many statements to execute as a truthful result of the condition, we should write the
statements on alternate lines.
 Of course, you can use this technique even if the condition you are examining is short.
 In this case, one very important rule to keep is to terminate the conditional statement with End If.

If expression Then
Statement
End If

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 59
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Here is another way:


If Condition Then
Statement1
Statement2
Statementn
End If

VB comparison operators:
< Less Than
<= Less Than or Equal to
> Greater Than
>= Greater Than or Equal to
= Equal to
<> Not Equal to

Example:
Private Sub Command1_Click()
Dim var1 As Integer
var1 = 10
If var1 = 10 Then
MsgBox "The condition is true."
End If
End Sub

2. If....Then. .. Else statement:


Description:
 The If.. Then statement offers only one alternative: to act if the condition is true.
 Whenever we would like to apply an alternate expression in case the condition is false we can use the
If...Then. Else statement.
Syntax:
If ( expression ) Then
Statement1
Else
Statement2
End If
 When this section of code is executed, if the expression is true, then the first statement, Statement1, is
executed.
 If the expression is false, the second statement, Statement2, is executed.
Example:
Private Sub Command1_Click()
Dim var1 As Integer
var1 = 5
If var1 = 10 Then
MsgBox "The variable is ten"
Else
MsgBox "The variable is not ten"
Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 60
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

End If
End Sub

The expression is evaluated. If the resulting value is non-zero, the statement(s) after the Then are executed.
If there is an Else and if the expression evaluated to zero, the statement(s) after the Else are executed.

3. Nested If statement:
Description: The If...Then...ElseIf statement acts like the If...Then...Else expression, except that it offers as
many choices as necessary.
Syntax:
If ( expression = value_1 ) Then
Statements_1
ElseIf ( expression = value_2) Then
Statements_2
ElseIf ( expression = value_3) Then
Statements_3

Else
Statements_default
End If
 The program will first examine expression1.
 If expression1 is true, the program will execute Statments1 and stop examining conditions.
 If expression1 is false, the program will examine expression2 and act accordingly.
 Whenever a condition is false, the program will continue examining the conditions until it finds one.
 Once a true condition has been found and its statement executed, the program will terminate the
conditional examination at End If.

Example:
Private Sub Form_Click()
If BackColor = vbRed Then
BackColor = vbBlue
ElseIf BackColor = vbBlue Then
BackColor = vbGreen
Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 61
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

ElseIf BackColor = vbGreen Then


BackColor = vbBlack
Else
BackColor = vbRed
End If
End Sub

4. Select statement:
Description:
If we have a large number of conditions to examine, the If...Then...Else will go through each one of them.
Visual Basic offers the alternative of jumping to the statement that applies to the state of the condition.

Syntax:
The formula of the Select Case is:

Select Case Expression


Case Expression1
Statement1
Case Expression2
Statement2
Case Expressionk
Statementk
End Select

 The Expression will examined and evaluated once.


 Then it will compare the result of this examination with the Expression of each case.
 Once it finds one that matches, it would execute the corresponding Statement.
 If there could be no match between the Expression and one of the Expressions,use a Case Else statement
at the end of the list.
 The statement would then look like this:

Select Case Expression


Case Expression1
Statement1
Case Expression2
Statement2
Case Expressionk
Statementk
Case Else
Statementk
End Select

Example:
Private Sub Form_Click()
Select Case BackColor

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 62
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Case vbRed
BackColor = vbBlue
Case vbBlue
BackColor = vbGreen
Case vbGreen
BackColor = vbBlack
Case Else
BackColor = vbRed
End Select
End Sub

THE GOTO
The Unconditional control transfer is performed using GoTo Statement.To use GoTo in VB, we must label a
line. Labels must begin with a letter and end with a colon. They must also start in the first column.
Syntax
GoTo LabelName
LabelName :
[Statements]

For Example:
If I=0 then
Goto AB
End If
AB:
MsgBox ―Using GoTo‖

STRING FUNCTIONS
A Built-In function is simply a prepackaged piece of code that accomplishes a single task. Visual Basic is
powerful in handling String functions. The some of the String functions are given below
Function name Syntax Description and its
usage
1.Space Space(NumberOfSpaces) Used to build up a
NumberOfSpaces-specifies the number of spaces string of spaces

2.String String(Number,StringExpression$) Used to build up a


Number-specifies the number of times the characters are string of repeated
repeated by the value specified in the first position characters
StringExpression-the first character of this expression is
repeated for the number of times that is specified in the first
position
3.Len Len(String) Used to count the
String –The expression used to find the length characters in a string
It will counts all the spaces and returns the length
as an integer

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 63
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

4.Trim Trim(String) Used to strip the


String-Expression that should be stripped off the trailing and trailing and leading
leading spaces spaces
5.LTrim LTrim(String) Used to strip the
String-Expression that should be stripped off the trailing and leading spaces
leading spaces
6.RTrim RTrim(String) Used to strip the
String-Expression that should be stripped off the trailing and trailing spaces
leading spaces
7.Lcase Lcase(String) Used to return a String
String -Expression that should be changed into lower case with all letters
converted into
lowercase.
8.Ucase Ucase(String) Used to return a String
String –Expression that should be changed into upper case with all letters
converted into
uppercase
9.Chr Chr(Charcode) Used to find the
Charcode-the number that identifies a character character associated
with the specified
character code
10.Asc Asc(String) Used to find the
String-String that identifies a character code character code
corresponding to the
first letter in a string
11.StrComp StrComp(String1,String2[,compare]) Returns a value
String1&String2 are any valid string expressions indicating the result of
Compare specifies the type of string comparision a string comparison
0-for case sensitive comparison Returns –1 when
1-for non case sensitive comparsions String1 < String 2
Returns +1 when
String1 > String2
Returns 0 when
String1 = String2
12.Rset RSet Stringvar=String Used to right align a
Stringvar is the name of the string variable string within a string
String is the String expression to be right –aligned within variable
Stringvar
13.Lset LSet Stringvar=String Used to left align a
Stringvar is the name of the string variable string within a string
String is the String expression to be left –aligned within variable
Stringvar

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 64
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

14.Left Left(String,Length) Returns characters


String is the string form which we are returning characters from the left hand side
Length is the number of characters to return of string

15.Right Right(String ,Length) Returns characters


String is the string form which we are returning characters from the right hand
Length is the number of characters to return side of string

16.Mid Mid(String, Start[,Length]) Returns characters


String is the string from which are we are returning characters from any part of a
Start is the character position in string at which the part to be string.
taken. If the start position is
Length is the number of character to return. If this is omitted not given, it usually
then all characters from the start position to the end of the starts from the first.
string are returned. If the length is not
specified it takes out
the all the characters
from the starting
position.
17.Split Split(Expression[,delimiter[,count[,compare]]]) Used to split a string
Expression is the original string that is used for searching at its space or can do
Delimiter parameter is the String that marks the break. more using delimiter
Count specifies the number of sub strings we want in the array
Compare parameter specifies whether case sensitive or case
insensitive
It takes the value
0-VbBinaryCompare-Case Sensitive
1-VbTextCompare-CaseInsensitive
18.InStr InStr([Where to Start,]String to search, String to find) Returns the first
(Or) position of a string
InStr([start,]String1,String2[,compare]) inside another string.If
the substring is not
Where to Start is a numeric expression that sets the start found,InStr returns a 0
position for the search of sub string in string. If Start position is
omitted, Instr begins searching at the first position 1.
String to Search is the string being searched.
String to find is the string we are looking for in original string

Compare parameter specifies whether case sensitive or case


insensitive
It takes the value
0-VbBinaryCompare-Case Sensitive
1-VbTextCompare-CaseInsensitive

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 65
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

19.InStrRev InStrRev (OriginalString, SubString [, Start Returns the first


[, Compare ]]) position of a string
OriginalString is the string being searched from the back end inside another string.If
of the string(i.e from the last.) the substring is not
SubString is the string that we are looking for in original string found, InStrRev
Start is a numeric expression that sets the start position for the returns a 0.
search of sub string in string. If Start position is omitted, Typically this function
InstrRev begins searching from the last position is used for finding the
extensions of the file

20.Replace Replace(Expression, Find, ReplaceWith [, Start [,count [, Used to replace a


compare ] ] ] ) string with another
Expression is the original string that is used for searching. If string. (i.e. it changes
the original string is null or omitted, the resulting string is an the size of the actual
error string.)
Find is the string that we are looking for in original string.If the
Find parameter is omitted,the resulting string is the original
string
ReplaceWith is the alternate string to be substituted for the
string that is found is the original string If the ReplaceWith is
omitted or VbNullString , the resulting string is the Original
string
Start specifies the start position for the search of sub string in
original string. If Start parameter is 0 or omitted, it starts
searching from the first location. If Start parameter is greater
than the length of the original string, the resulting string is an
empty string
Count specifies the number of times we want to do the
substitution, if there are multiple copies of the same string
inside the original string. If Count Parameter is 0 or omitted,
the resulting string is the original string.
Compare specifies case sensitive or not
21.Like String1 Like String2 Used to compare
String1 and String2 are valid String Expressions. String using wild
It uses wild card characters for comparing two strings cards
Match Pattern character Returns True if it
Any Single Character ? found match
Zero or more characters * Returns False If it is
Any single Digit # not matching.
Any single characters in the list [list of characters]
Any single characters not in the list [! list of characters]

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 66
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

NUMERIC FUNCTIONS
Visual Basic is powerful in handling Numeric functions. The some of the Numeric functions are given below
Function
Syntax Description and its usage
name
1.Fix Fix( Expression) Used to throw away the decimal
Expression is any valid numeric expression or number part of the number
2.Round Round(Expression[,number of decimal places]) Used to round the number to the
Expression is any valid numeric expression or number nearest possible integer
Number of decimal places specifies to round past the
decimal point
3.Sgn Sgn(Expression) Returns:
Expression is any valid numeric expression or number +1 If number is greater than 0;
0 If number is equal to 0;
-1 If number is less than 0;
4.Abs Abs(Expression) Returns the absolute value of the
Expression is any valid numeric expression or number number
5.Sqr Sqr(Expression) Returns the square root of number
Expression is any valid numeric expression or number
6.Exp Exp(Expression) Returns e raised to the power of
Expression is any valid numeric expression or number the number(e=2.7182)
7.Log Log(Expression) Returns the natural logarithm of
Expression is any valid numeric expression or number number
8.Sin Sin(Expression) Returns the sine value of number.
Expression is any valid numeric expression or number The number expresses an angle in
radians.

9.Cos Cos(Expression) Returns the Cosine value of


Expression is any valid numeric expression or number number. The number expresses an
angle in radians.

10.Tan Tan(Expression) Returns the Tangent value of


Expression is any valid numeric expression or number number. The number expresses an
angle in radians.

11.Int Int(Expression) Returns the Integer portion of


Expression is any valid numeric expression or number number.

12.Atn Atn(Expression) Returns the arc tangent of


Expression is any valid numeric expression or number number. Returns an angle in
radians.

13.Rnd Rnd(Expression) Returns a random number less


Expression is any valid numeric expression or number than 1 but greater than or equal to
0.

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 67
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

DATE AND TIME FUNCTIONS


Working with Dates and Times
Visual Basic, dates and times are stored internally as numbers. The whole number portion of the number
represents the date between January 1,100 and December 31, 9999, inclusive, with each incrementing the
number by one. The decimal portion of the number represents the time between 0:00:00 and
23:59:59,inclusive.Vb is powerful in handling the date and time functions. These functions are given below
Type of
Function Syntax language Value Displayed
Element
1. Now Now Function Returns the current date and
time from our computer‘s
Built-in clock
2. Date Date Function/S Reads or sets the date from our
tatement computer‘s clock
3. Time Time Function/S Reads or sets the time from our
tatement computer‘s clock
4. IsDate IsDate(StrExp) Function Returns a Boolean indicating
StrExp- any valid expression whether or not the string is a
valid date
5. DateValue DateValue(DateExp) Function Optional,returns a date
DateExp-any valid date expression datatype from a string
representation of a date
6. TimeValu TimeValue(DateExp) Function Optional,returns a date
e DateExp-any valid date expression datatype from a string
representation of a date
7. Date Day(DateExp) Function Returns an integer representing
DateExp-any valid date expression the day portion of the date
parameter
8. Month Month(DateExp) Function Returns an integer representing
DateExp-any valid date expression the month portion of the date
parameter
9. Year Year(DateExp) Function Returns an integer representing
DateExp-any valid date expression the year portion of the date
parameter
10. Hour Hour(time) Function Returns an integer representing
time-any valid time the hour portion of the time
parameter
11. Minute Minute(time) Function Returns an integer representing
time-any valid time the minute portion of the time
parameter
12. Second Second(time) Function Returns an integer representing
time-any valid time the second portion of the time
parameter
13. DateSerial DateSerial(Year,Month,Day) Function Returns an date datatype from
Year takes the value from 0 to 9999 a year, month and day

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 68
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Month takes the value from 1 to 12


Day takes the value 30 or 31
If the value of the month or day is
greater than its limit, it wraps into the
next year or month
E.g. DateSerial(1999,14,2)-valid date
in the month of February ,2000
14. TimeSeria TimeSerial(Hours,Minutes,Seconds) Function Returns an date datatype from
l Wrapping capability is also present a year, month and day
E.g. TimeSerial(5,71,2)-valid time
equivalent to 6:11:2
15. WeekDay WeekDay(Date,[Firstday of week]) Function Returns the day of the week
Date –any valid date
Firstday of week takes the values
between 1 to 7 ,which is used to start
the week in different way.
Constant Value
VbSunday(Default) 1
VbMonday 2
VbTuesday 3
VbWednesday 4
VbThursday 5
VbFriday 6
VbSaturday 7
16. Timer Timer Function Returns the number of seconds
past midnight.
17. DateAdd DateAdd(Interval,Number,Date) Function Used to add the year or month
The first parameter,Interval,is the or day to the original date
string that represents the type of
interval that is being added to or
subtracted from the date in the third
parameter. The Interval string must be
one of the values summarized below:
Interval Description
yyyy year
q quarter
m month
y day of year
d day
w weekday
ww week

The second parameter, Number, is


along integer that represents the
number of units of type interval to add

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 69
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

to the date in the third parameter. If


Number is negative, the function
subtracts the number of intervals,
rather than adding..
The third parameter, Date, must be a
date variable that contains a valid date.
18. DateDiff DateDiff(Interval,Date1,Date2[,First Function Returns the difference between
Day of Week]) two date in the interval that we
Interval parameter is the string that select.
denotes the interval in which the
difference should be expressed. The
same settings are used as those listed in
the DateAdd function.
Date1& Date2 are valid two date
expressions or date variables
Firstday of week is already explained
in the WeekDay function
19. DatePart DatePart(Interval,Date[,Firstday of Function Returns the part of the date
week]) specified.
Uses the same interval settings

FINANCIAL FUNCTIONS
Visual Basic comes with a library of financial functions for handling standard calculations that everyone will
occasionally need to do. Before going to financial functions, we have to see the definition for the terms such
as annuity, and what its value in the Mortgage and Retirement calculation. An annuity is a fancy term for a
series of payments made over time. For example, In Mortgage calculation, we have to start out with a (large)
amount, make (many) payments over time, and end up with a zero balance. In the retirement calculation we
made periodic payments over time and thereby ended up with a (large) amount of money at the end.
Function Syntax
Pmt (Pay out Pmt (RatePerPeriod, NumPeriods, WhatYouStartWith, WhatYouEndUpWith,
for annuity) WhenDoYorPay)
RatePerPeriod-Interest rate is quoted per year, but payment is every month. This entry
needs the interest rate per payment rate i.e. the interest rate should be divided by 12
NumPeriods- number of periods
WhatYouStartWith-i.e the initial balance
WhatYouEndUpWith-In Mortgage, this would be zero,For savings plan, this would be the
amount we want to end up with for retirement
WhenDoYouPay-tells about the payment to be paid at the beginning of the period or at the
end. Use a 0 for the end of the month and a 1 for the beginning. In all the entries (and the
result as well), moneys paid out are represented by negative numbers; moneys received are
represented by positive numbers.

Syntax in the System


Pmt(rate,nper,pv[,fv[,type]])

Mrs.S.PUNITHAVLLI.,MSc.CS(DA)., 70
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Fv-Future Value FV(InteresetRatePerPeriod, NumPeriods,PaymentPerPeriod [, StartAmount


[,WhenDue ]])

Syntax in the System


FV(rate,nper,pmt[,pv[,type]])
IPmt-Interest Paid Over Ipmt(rate,per,nper,pv,fv,due)
Time Rate is the interest rate per period, and per is the period in the range 1 through
the number of periods(nper)
Nper-Number of Nper(rate,pmt,pv,fv,due)
deposits/withdrawals) to
accumulate (disburse) an
annuity
PV-Present value PV(rate,nper,pmt,fv,due)
Rate is as usual, the interest rate per period, nper is the total number of
payments made, pmt is the number of payments made each period. The fv entry
is the future value or cash balance we want after we have received(made) the
final payment.
NPV-Net Present value NPV(RatePerPeriod,ArrayOf())
ArrayOf() allows the amounts received or disbursed to change over time.
Rate-Interest rate per Rate(n per,pmt,pv,fv,due,guess)
period for an annuity Rate function uses an iterative procedure to arrive at he true interest rate.
Answer Rate is calculated by iteration.Vb starts with the value of guess and
repeats the calculation until is accurate to within 0.00001 percent.It starts with
the value 0.01.If , after 20 tries, it can‘t find a result, the function fails.If the
function fails, try a different value for guess
SLN and DDB-Straight SLN(cost,Salvage value,Life Expectancy) and
line and Double DDB(cost,Salvage value,Life Expectancy,Period of Calculation)
declining balance
depreciation of an asset
over a given period
IRR,MIRR-Internal Rate IRR(ValueArray(),Guess)
of Return, and Modified and
rate of return MIRR(ValueArray(),FinanceRate,Reinvestrate)
ValueArray() contains the receipts and disbursements .

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 72
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

UNIT - IV
Function Procedures – Sub Procedures – Advanced Uses of Procedures and Functions – Lists: One–
Dimensional Arrays – Arrays with more than One–Dimension - Using Lists and Arrays with Functions and
Procedures – The With Statement - Enums – Control Arrays – List and Combo Boxes
– Menus – Menu Editor – MDI Forms
THE ANATOMY OF A PROCEDURE:
The procedure or Subroutine is the piece of code that gets executed when the control that it is
associated with senses an event. The event means mouse click, mouse move or method invoked bythe code.
Parts of a Procedure or Subroutine:
A procedure consists of the following things:
1. Name
2. Declaration Area
3. Statements
4. Call to Other procedures and/or functions.
5. Terminator.
1. Name:
Every procedure must have a name. The name of a procedure is usually tied to the control. You can
have a procedure called cmdExit_clcik(). This means that this procedure will be executed against the
―Click‖ event of the ―cmdExit‖ button. The ―Sub‖ before the name means that the procedure is a
Subroutine.

2. Declaration Area:
This area is used to declare all the variables, constants etc. However it is considered a good idea to
declare the entire variable at the beginning of the procedure. This makes it easy to locate variables and verify
the same during the process of debugging.

3. Statements:
The procedure deals with basic execution. Procedure will contain VBA (Visual Basic Application)
statements (or code if you like) that will perform the intended task. A procedure can have as many
statements as you care to add but keeping your procedures short and simple will render them easy to debug.

4. Call to other Procedures and/or Functions:


One way of reducing the number of lines in a procedure is to break up the entire activity into smaller
functions or procedures that can be called as and when required. Therefore, if a particular task has to be
performed by more than one event that task can be written as and when required.
The principle used here is ―Write once use many times‖. A call to another procedure or
function is not a must for every procedure.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 73
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

5. Terminator:
All good things come to an end. Every procedure (subroutine in the case) is terminated by the
―End Sub‖ statement.

Introduction to Procedures:
We can simplify programming tasks by breaking programs into smaller logical components. These
components — called procedures — can then become building blocks that let us to enhance and extend
Visual Basic.
Procedures are useful for condensing repeated or shared tasks, such as frequently used calculations, text and
control manipulation, and database operations.
There are two major benefits of programming with procedures:
 Procedures allow breaking our programs into discrete logical units, each of which we can
debug more easily than an entire program without procedures.
 Procedures used in one program can act as building blocks for other programs, usually with
little or no modification.
There are several types of procedures used in Visual Basic:
 Sub procedures do not return a value.
 Function procedures return a value.
 Property procedures can return and assign values, and set references to objects.

In order to add a Procedure in our program,


1. The code window is opened for the module to which the procedure is to be added.
2. Add Procedure is chosen from the Tools menu, which opens an Add Procedure dialog
box shown below.
3. The name of the procedure is typed in the Name Textbox.
4. Under Type, Sub is selected to create Sub Procedure, Function to create a Function
Procedure, or Property to create a Property Procedure.
5. Under scope, public is selected to create a procedure that can be invoked from outside
the module, or private to create a procedure that can be invoked only from within the
module.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 74
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

FUNCTION PROCEDURES
Visual Basic includes built-in, or intrinsic functions, like Sqr, Cos or Chr.
In addition, we can use the Function statement to write our own Function procedures.The
syntax for a Function procedure is:
[Private|Public][Static]Function procedurename (arguments) [As type]
statements
End Function
Like a Sub procedure, a Function procedure is a separate procedure that can take arguments, perform
a series of statements, and change the value of its arguments. Unlike a Sub procedure, a Function procedure
can return a value to the calling procedure. There are three differences between Sub and Function
procedures:
 Generally, we can call a function by including the function procedure name and arguments
on the right side of a larger statement or expression (return value = function()).
 Function procedures have data types, just as variables do. This determines the type of the
return value. (In the absence of an As clause, the type is the default Variant type.)
 We can return a value by assigning it to the procedure name itself. When the Function
procedure returns a value, this value can then become part of a larger expression.
For example, we can write a function that calculates the third side, or hypotenuse, of a right triangle, given the
values for the other two sides:
Function Hypotenuse (A As Integer, B As Integer) As String
Hypotenuse = Sqr(A ^ 2 + B ^ 2)
End Function
We can call a Function procedure the same way we call any of the built-in functions in Visual Basic:
Label1.Caption = Hypotenuse(CInt(Text1.Text), CInt(Text2.Text))strX = Hypotenuse(Width, Height)

Example: (Function)
Public Function Sum(n1 As Integer, n2 As Integer) As Integer
Sum=n1+n2
End Sub
The function ―Sum‖ called anywhere in the program. It can be called by simply passing the variables to it as
arguments. Consider the following event procedure.

Event Procedure:
Private Sub CmdFun1_Click()
Dim M1 As Integer Dim
M2 As Integer Dim Tot As
Integer
M1=val(Text1.Text)
M2=val(Text1.Text)
Tot=Sum(m1,m2)
End Sub

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 75
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

SUB PROCEDURES
A Sub procedure is a block of code that is executed in response to an event. By breaking the code ina
module into Sub procedures, it becomes much easier to find or modify the code in our application. The
syntax for a Sub procedure is:
[Private|Public][Static] Sub procedure name (arguments)
Statements
End Sub

Each time the procedure is called, the statements between Sub and End Sub are executed. Sub procedures
can be placed in standard modules, class modules, and form modules. Sub procedures are by default Public in
all modules, which means they can be called from anywhere in the application.

Example:
In this example, we create a sub procedure to sum up two values that are specified by the arguments The
main program can reference a procedure by using its name together with the arguments in the parentheses.
Private Sub cmdCal_Click()
Dim x As Single, y As Singlex
= Val(TxtNum1.Text)
y = Val(TxtNum2.Text)
sum x, y
End Sub

Sub sum(a As Single, b As Single)


MsgBox ("sum=" & a + b)
End Sub
Running the program produces a message boxes as shown in Figure.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 76
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Differentiate Subroutines and Functions


SUBROUTINES (OR) PROCEDURES FUNCTIONS
Subroutines are procedures that are executes as a Functions are procedures that are executed as a
unit of code. unit of code
Subroutines will not return any value to the Function will return a value to the calling program
calling program. and can therefore be used as a variable in order to
return a value.
The subroutine declared with ―Sub‖ keyword and The Function declared with the ―Function‖
terminated with ―End Sub‖ statement. keyword and terminated with the ―End Function‖
statement.

ADVANCED USES OF PROCEDURES AND FUNCTIONS


1. Calling Procedures:
The techniques for calling procedures vary, depending on the type of procedure, where it's located, and how
it's used in your application. The following sections describe how to call Sub Function and procedures.

2. Calling Sub Procedures:


A Sub procedure differs from a Function procedure in that a Sub procedure cannot be called by using its
name within an expression. A call to a Sub is a stand-alone statement. Also, a Sub does not return a value in
its name as does a function. However, like a Function, a Sub can modify the values of any variables passed to
it.
There are two ways to call a Sub procedure:

' Both of these statements call a Sub named MyProc.Call MyProc (FirstArgument,
SecondArgument)
MyProc FirstArgument, SecondArgument

Note that when we use the Call syntax, arguments must be enclosed in parentheses. If we omit the Call
keyword, we can also omit the parentheses around the arguments.

3. Calling Function Procedures:


Usually, we call a function procedure we've written our self the same way we call an intrinsic Visual Basic
function like Abs; that is, by using its name in an expression:

' All of the following statements would call a function' named ToDec.

Print 10 * ToDecX =
ToDec
If ToDec = 10 Then Debug.Print "Out of Range"X =
AnotherFunction(10 * ToDec)

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 77
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

It's also possible to call a function just like we would call a Sub procedure. The following statements both call
the same function:

Call Year(Now)Year
Now

When you call a function this way, Visual Basic throws away the return value.

4. Calling Procedures in Other Modules:


Public procedures in other modules can be called from anywhere in the project. We might need to specify the
module that contains the procedure we're calling. The techniques for doing this vary, depending on whether
the procedure is located in a form, class, or standard module.

5. Procedures in Forms(or Form Modules):


All calls from outside the form module must point to the form module containing the procedure. If a
procedure named SomeSub is in a form module called Form1, then we can call the procedure in Form1 by
using this statement:

Call Form1.SomeSub(arguments)

6. Procedures in Class Modules:


Like calling a procedure in a form, calling a procedure in a class module requires that the call to the
procedure be qualified with a variable that points to an instance of the class.
For example, DemoClass is an instance of a class named Class1:

Dim DemoClass as New Class1


DemoClass.SomeSub
However, unlike a form, the class name cannot be used as the qualifier when referencing an instance
of the class. The instance of the class must be first be declared as an object variable (in this case,
DemoClass) and referenced by the variable name.

7. Procedures in Standard Modules:


If a procedure name is unique, we don't need to include the module name in the call. A call from inside or
outside the module will refer to that unique procedure. A procedure is unique if it appears only in one place.

If two or more modules contain a procedure with the same name, we may need to qualify it with the module
name. A call to a common procedure from the same module runs the procedure in that module. For example,
with a procedure named CommonName in Module1 and Module2, a call to CommonName from Module2
will run the CommonName procedure in Module2, not the CommonName procedure in Module1.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 78
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

A call to a common procedure name from another module must specify the intended module. For example, if
you want to call the CommonName procedure in Module2 from Module1, use:

Module2.CommonName(arguments)

8. Passing Arguments to Procedures:


Usually the code in a procedure needs some information about the state of the program to do its job. This
information consists of variables passed to the procedure when it is called. When a variable is passed to a
procedure, it is called an argument.

9. Argument Data Types:


The arguments for procedures we write have the Variant data type by default. However, we can declare other
data types for arguments. For example, the following function accepts a string and an integer:

Function WhatsForLunch(WeekDay As String, Hour As Integer) As String


' Returns a lunch menu based on the day and time.

If WeekDay = "Friday" then


WhatsForLunch = "Fish"
Else
WhatsForLunch = "Chicken"End If
If Hour > 4 Then WhatsForLunch = "Too late"End Function

10. Passing Arguments By Value:


Only a copy of a variable is passed when an argument is passed by value. If the procedure changes the value,
the change affects only the copy and not the variable itself. Use the ByVal keyword to indicate an argument
passed by value.

For example:
Sub PostAccounts(ByVal intAcctNum as Integer)
.
. ' Place statements here.
.
End Sub

11. Passing Arguments By Reference:


Passing arguments by reference gives the procedure access to the actual variable contents in its memory
address location. As a result, the variable's value can be permanently changed by the procedure to which it is
passed. Passing by reference is the default in Visual Basic.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 79
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

If we specify a data type for an argument passed by reference, we must pass a value of that type for the
argument. we can work around this by passing an expression, rather than a data type, for an argument. Visual
Basic evaluates an expression and passes it as the required type if it can.
The simplest way to turn a variable into an expression is to enclose it in parentheses. For example, to pass a
variable declared as an integer to a procedure expecting a string as an argument, you would dothe following:

Sub CallingProcedure()Dim intX


As IntegerintX = 12 * 3
Foo(intX)
End Sub

Sub Foo(Bar As String)


MsgBox Bar 'The value of Bar is the string "36".
End Sub

12. Using Optional Arguments:


We can specify arguments to a procedure as optional by placing the Optional keyword in the argument list.
If we specify an optional argument, all subsequent arguments in the argument list must also be optional
and declared with the Optional keyword. The two pieces of sample code below assume there is a form with a
command button and list box.
For example, this code provides all optional arguments:
Dim strName As String Dim
strAddress As String

Sub ListText(Optional x As String, Optional y _As String)


List1.AddItem x
List1.AddItem y
End Sub

Private Sub Command1_Click()strName =


"yourname"
strAddress = 12345 ' Both arguments are provided.Call
ListText(strName, strAddress)
End Sub

This code, however, does not provide all optional arguments:

Dim strName As String


Dim varAddress As Variant

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 80
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Sub ListText(x As String, Optional y As Variant)List1.AddItem x


If Not IsMissing(y) Then
List1.AddItem y
End If
End Sub

Private Sub Command1_Click()


strName = "yourname" ' Second argument is not
' provided.
Call ListText(strName)End Sub
In the case where an optional argument is not provided, the argument is actually assigned as a variant with
the value of Empty. The example above shows how to test for missing optional arguments using the
IsMissing function.

13. Providing a Default for an Optional Argument:


It's also possible to specify a default value for an optional argument. The following example returns a
default value if the optional argument isn't passed to the function procedure:

Sub ListText(x As String, Optional y As Integer = 12345)List1.AddItem x


List1.AddItem yEnd
Sub

Private Sub Command1_Click()


strName = "yourname" ' Second argument is not provided.Call
ListText(strName) ' Adds "yourname" and "12345".
End Sub

LISTS: ONE–DIMENSIONAL ARRAYS


What is Array?
A group of values can be stored in a single variable name with same data type is known as array.
Each array variable is known as array element. Array elements are referred by its subscripts. Subscripts are
always be a positive integer number.
Syntax:
Dim Array_VarName [(subscript)] As [New] type [,VarName…]

Example 1:
Dim Num(5) As Integer
―Num‖ is the set of 6 integers.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 81
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Nums(0) is the first element.


Nums(5) is the sixth and the last element.
The numbers inside the parentheses of the individual variables are called subscripts, and each individual
variable is called a subscripted variable or element. The elements of an array are assigned successive
memory locations. The following figure shows the memory location for the array Num(5)

Example 2:
Dim X(10 To 20) As Integer
―X‖ is the set of 11 integers.
X(10) is the first element.
X(20) is the eleventh and the last element.

What are the types of


Array?Types of Array:
Two types of arrays:
1. One Dimensional Array Only One Subscript
2. Multi-Dimensional Array (or) Arrays with more than one dimension More
than one Subscript

ONE-DIMENSIONAL ARRAYS:
Declaring Fixed Size Arrays:
The scope of the array will depend upon the method of declaration.
1. To create a local array, use the Dim statement in a procedure to declare the array.
Dim Sum(10) As Single
2. To create a Module array, use the Private statement in the Declaration section of a
module to declare the array.
Private Ser(10) As Single
3. To create a Public array, use the Public statement in the Declaration section of a form.
Public Sun(10) As Single
4. In the case of fixed – size array it is compulsory to enter the upper bound of the array in
the parenthesis.
5. The upper bound is the upper limit for the size of the array.

A declaration such as the following:


Example 1:
Private Counter(10) As Integer
The Counter array contains 11 elements.

To specify the lower bound of an array, provide it explicitly (as a long data type) using the TO
keyword.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 82
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Dim Counter(1 to 10) As Integer


In the above declaration, the index numbers of counter range from 1 to 10. The LBound is afunction
that returns the lower bound of an array.

Example
Dim X As Integer
Dim SinX(24) As Integer
X=Lbound(SinX)
Debug.Print X

ARRAYS WITH MORE THAN ONE–DIMENSION


Multi-Dimensional Array:
Arrays can have more than one dimension. A table of data will be represented by a multidimensional
array.
Example 1:
Dim Sales(11,2) As Integer
Here the Subscript 11 indicates the Months and the subscript 2 indicates the departments. This
is a two dimensional array.
Example 2:
Dim Sales(11,2,4) As Integer
Here the Subscript 11 indicates the Months, the subscript 2 indicates the departments and the
subscript 4 indicates the products. A multi-dimensional array takes up a lot of space.

Dynamic Arrays:
Dynamic arrays are used when the user doesn‘t know the number of elements of an array.
Advantages:
1. A dynamic array can be resized at any time and this helps us to manage memory efficiently.
2. We can use a large array for a short time and then a free memory to the system when we are
no longer using the array.
3. We can increase the size of the array after having declared a smaller array.
ReDim: ReDim is used to declare the array as dynamic by giving it an empty dimension list.
Declaring a Dynamic Array:
We declare the array as dynamic by giving it an empty dimension list
Dim a()
Use the ReDim statement to allocate the actual number of elements.
ReDim
a(11,4)Example:
Dim a() As Integer
This statement will create an open –ended array
ReDim a(12,6)
This will create a two-dimensional array.
The values for the subscript of the array can be passed using variables.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 83
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Example:
Dim a() As Integer Dim
Months As IntegerDim
Depts As Integer
Months = 12
Depts = 4
ReDim a(Months, Depts)

ReDim Statement: The ReDim statement is used at procedure level to relocate storage space for
dynamic array variables.
Syntax:

ReDim [ Preserve] Var_Name(Subscript)[As type]


Preserve is a keyword to preserve the data in an existing array when we change the size of the lastdimension.
VarName is the name of the variable.
Subscript is the dimension of an array variable.
Type is the data type of the variable.

More on ReDim:
Only the upper bound of the last dimension in a multidimensional array can be changed when we usethe
Preserve keyword. If we change any other dimension, a run-time error will occur.
Example:
Dim a(11,2,4) As Integer
It can be resized using the Preserve keyword.
Example:
This example uses the ReDim statement to allocate and reallocate storage space for dynamicarray
variables.
Private Sub Form_Load()
Dim a() As Integer
ReDim a(5)
For i= 1 to 5
a(i)= i
Next i
End Sub

THE WITH STATEMENT


It executes a series of statements, making repeated reference to a single object or structure.
With object
[Statements]
End With

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 84
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Object: [Required] Variable or expression. Can evaluate to any data type, including elementarytypes.
Statements: [Optional] One or more statements between With and End With that run on object.
End With: [Required] Terminates the definition of the With block.
Example:
With yourname
.Name=‖howard‘
.Salary=100000
.Socsec=‖036-78-9987‖
End With

ENUMS
An enumeration, or Enum , is a symbolic name for a set of values. Enumerations are treated asdata
types, and we can use them to create sets of constants for use with variables and properties

Declare Enum
An Enum type has a name, an underlying type, and a set of fields, each representing a constant.
The name must be a valid Visual Basic qualifier. The underlying type must be one of the integertypes—
Byte, Short, Long or Integer. Integer is the default.
Example:
Public Enum Days
Sunday=1
Monday Tuesday
Wednesday
Thursday
Friday
Saturday
End Enum

VB automatically assigns successive integer to the days of the week.


Monday=2
Tuesday=3 and so on.

The benefits of using enumerations include:


Reduces errors caused by transposing or mistyping numbers.
Makes it easy to change values in the future.
Makes code easier to read, which means it is less likely that errors will creep into it.
Ensures forward compatibility.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 85
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

CONTROL ARRAYS
Array is the collection of similar elements. Control Array is nothing but, collection of similar controls. These
controls are the elements of the Control array, which share the common properties. There are three ways to
create control arrays in Visual Basic, are
 Using CTRL+C, CTRL+V to copy an existing control from one place on the form to another
 Using the same control name for the controls in the form, more than once while designing a
visual basic application.
 Using the index property of the controls
Working with a Control Array
Change procedure of a control present in the control array is different from the change procedure of the
ordinary control. The Change procedure of the control Array will have index as parameter. This parameter is
the key to the smooth functioning of control arrays.
Adding and Removing Controls in a Control Array
We can inadvertently add a control to a control array at design time; we can also remove it by changing the
control name or deleting the control at design time. The nifty part is that once we‘ve created array at design
time, we can add controls while the application is running. To do this, we use a method called Load
The Syntax for Load method is
Load ControlArrayName (Index)
Suppose we want to add three textboxes in the control array at run time, where there is a textbox
already created at run time. We have to write the following code to the form_load event procedure toadd
three textboxes at runtime.
Private Sub Form_Load()
Dim I As Integer
Const Spacing = 10
Text1(0).Move 0, 0
Text1(0).Text = "Text box in control Array #0" Text1(0).Width =
TextWidth(" Text box in control Array # 0 ")For I = 1 To 3
Load Text1(I)
Text1(I).Text = "Text box in control Array #" + Str(I) Text1(I).Width =
TextWidth(" Text box in control Array # " + Str(I))Text1(I).Move 0,
Text1(I - 1).Top + Text1(I - 1).Height + Spacing Text1(I).Visible = True
Next
IEnd Sub
At run time, we have to set the Visible property of the new control to true or else the new elements will not
appear on the form. We should properly position the controls in the form using the Move method, this
means that the newly created controls in a control array default to being stacked one ontop of the other.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 86
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

The UnLoad Method is used to remove the controls from the control Array at run time
The Syntax of the UnLoad method is
UnLoad ControlArrayName(Index)
The following code will remove the text boxes from the control array which are created during run
time.
Private Sub Form_Click()
Static J As Integer If
J < 3 Then
Unload Text1(J + 1)J
=J+1
Else
Exit Sub
End
IfEnd Sub

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 87
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

LIST AND COMBO BOXES


List boxes contains list of items
The combo boxes allow users to input data as well as make choices from a list.
ListBox and ComboBox controls present a set of choices that are displayed vertically in a single
column.
If the number of items exceed the value that can be display, scroll bars will automatically appear onthe
control. These scroll bars can be scrolled up and down or left to right through the list.

Adding items to a list


It is possible to populate the list at design or at run time.
1. Design Time: To add items to a list at design time, click List in the property box and then
add the items. Press CTRL + ENTER after adding each item.
We can track the total number of items in a list box using ListCount property.
2. Run Time: The AddItem method is used to add items to a list at run time. The AddItem
method uses the following syntax:
List1.AddItem (item), Index
The item argument is string that represents the text to add to the list.
The index argument is an integer that indicates where in the list to add the new item.
addItem method is written as:
Private Sub Form_Load()
List1.AddItem (―Item 1‖)
List1.AddItem (―Item 2‖)
List1.AddItem (―Item 3‖)
List1.AddItem (―Item 4‖)
List1.AddItem (―Item 5‖)
List1.AddItem (―Item 6‖)
End Sub

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 88
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Removing Items from a List


The RemoveItem method is used to remove an item from a list. The syntax for this is given below.
Object.RemoveItem.index

Sorting the List


To sort the list set Sorted property to True at runtime or design time.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 89
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Selecting an Item from a list


To access the items in a listbox we use the ListIndex and List properties.
The list index property sets the index number of the currently selected item.
The first item in the list having index number 0.
ListIndex return -1 if no item is selected. The ListCount return total number of items in
listbox.

Using ComboBox
A Combo Box combines the features of Textbox. This control enables the user to select either bytyping
text into combo box or by selecting an item from list.
There are three types of Combo Box styles that are given below.
1. Dropdown Combo (style 0)
2. Simple Combo (style 1)
3. Dropdown list (style 2)

We select which type we want with the combo box Style property

A combo box is a combination of a text box and list box, so that at design time, we can change thetext in
the text box part by changing the Text property.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 90
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

At run time we add items in the combo box using AddItem method
Example:
Private Sub Form_Load()
cmb1.AddItem "test1"
cmb1.AddItem "test2"
cmb1.AddItem "test3"
End Sub

Events of combo box:


There are two main events of combo box: Click and Dblclick.

Remove items from combo box:

Sorting combo box:

Clearing a combo box:

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 91
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

MENUS
Creating and managing menu at Design Time:
Visual Basic applications can be enhanced by adding menus to it. It offers a convenient and
consistent way to group commands and easy way for users to access them.

The menu bar appears appear below the title bar and it may contain one or more menu titles.
When a menu title is clicked it displays a set of menu items under that title. Each menu item corresponds
to a menu control that is defined in a menu editor and performs a specific action.

MENU EDITOR
A menu editor can be used to add new commands to the existing bars. A menu editor can be added only after
opening a project. To display a menu editor command is chosen from the Tools menu or menu editor button
is clicked in the tool bar.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 92
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

1. Caption: This is the name that the user will see.


2. Name: This is the name that the programmer uses , we use the mnu prefix for all
menu items(mnuFile).
Shortcut: this assigns a shortcut to a menu item this is a combination of keys which access a menu item
for example Ctrl + c is commonly used for copy
3. Checked: this allows the programmer to place a check beside a menu item , this is
unchecked by default.
4. Enabled: This specifies whether the menu item is accessible to the user , if this is checked
the menu item is grayed out and inaccessible.
5. Visible: this determines whether the menu item is visible if this is not checked then the menu
item will not appear at run time.
6. Window List: determines whether the menu item applies to an MDI document (Word and
Excel are examples of MDI applications).
7. HelpContextID: this matches a help description if you have any in your program.
8. Index: this specifies a menus index in a control array.

Writing Code form menu Control


Each menu control has click event, which is execute when the menu item is selected orclicked.
The following code is entered in the code window for green color option of menu.
Private sub grn_Click()
Form1.backcolor= QBcolor(2)
Grn.Enabled = False
Blue.Enabled = True
Red.Enabled = True
End sub
When the green color is selected by clicking on it, form backcolor will be change into green colorand that
green option form menu is make disable and to other‘s enable.

Adding a Separator Bar and Shortcut key.


Separator bar is a line that separates the menu items, which is mainly useful for obtaining clarity. Toadd it in
menu, Right click on the form select menu editor
Place the pointer where you want to insert separator In
the caption TextBox ‗-‗ is typed and give any name

Using Access and Shortcut keys


Access keys allow the user to open a menu by pressing the Alt key with a letter key. To open theEdit
menu in all Windows applications, for e.g. you can press Alt-E. .
Access key is designed by the programmer and they are marked with an underline character. Toassign
Access key to menu item, add & sign before letter. e.g. ―&File‖.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 93
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Shortcut Keys
Shortcut keys are similar to access key has a special meaning in menu design, but inside a opening menu,
they run a command when pressed. To assign a shortcut key to a menu command, dropdown the shortcut list
in the menu editor and select a keystroke.

Sample Menu Editor:


Open a new Project and save the form as menu.frm and save the project as menu.vbp.
Choose Tools ››› Menu Editor and type the menu items as shown below.
Caption Name
File mnuFile
Open mnuOpen
Save mnuSave
Exit mnuExit
Edit mnuEdit
Copy mnuCopy
Cut mnuCut
Paste mnuPaste

Run the application by pressing F5. We can see that you can select a menu

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 94
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

MDI FORMS:
MDI stands for Multiple Document Interface.
The Multiple Document Interface (MDI) was designed to simplify the exchange of
information among documents.
Each document is displayed in its own window, and all document windows have the same
behavior.
The main Form, or MDI Form, isn't duplicated, but it acts as a container for all the windows,
and it is called the parent window.
The windows in which the individual documents are displayed are called Child windows.
An MDI application must have at least two Form, the parent Form and one or more child
Forms. Each of these Forms has certain properties.
There can be many child forms contained within the parent Form, but there can be only one
parent Form.
The parent Form may not contain any controls.
While the parent Form is open in design mode, the icons on the ToolBox are not displayed,
but can't place any controls on the Form.
The parent Form usually has its own menu.
To create an MDI application, follow these steps:
1. Start a new project and then choose Project >>> Add MDI Form to add the parent Form.
2. Set the Form's caption to MDI Window
3. Choose Project >>> Add Form to add a SDI Form.
4. Make this Form as child of MDI Form by setting the MDI Child property of the SDI Form to
True. Set the caption property to MDI Child window.

Restrictions of the MDI form


Can have only one MDI form per project.
Can't place most controls on an MDI form.
The only controls that can be placed on the surface of the MDI form are Menus, Timer,
CommonDialog, PictureBox, ToolBar, and StatusBar.
These restrictions are there because MDI forms are the special type of forms, especially used
to handle multiple child forms.
Restrictions of the MDI child forms:
1. Can't display an MDI child form outside its parent.
2. Can't display a menu bar on the MDI child form.

How does the MDI form work:


 There can be only one MDI parent form in a project with one or more MDI child forms (or
simply child forms).
 The parent form contains a menu bar on top of it.
 From there, the user opens or creates a new document.
 In this way, the user accomplishes his/her work in one or multiple documents, then saves and
closes the document (form).

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 95
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Following example illustrates the above explanation.


* Open a new Project and name the Form as Menu.frm and save the Project as Menu.vbp
* Design a menu that has the following structure.
<> MDIMenu Menu caption
MDIOpen opens a new child Form
MDIExit terminates the application
* Then design the following menu for the child Form
<> ChildMenu Menu caption
Child Open opens a new child Form
Child Save saves the document in the active child Form
Child Close Closes the active child Form
At design time double click on MDI Open and add the following code in the click event of the openmenu.
Form1.Show
And so double click on MDI Exit and add the following code in the click event
End
Double click on Child Close and enter the following code in the click event
Unload Me
Before run the application in the project properties set MDI Form as the start-up Form. Save and runthe
application. Following output will be displayed.

When we click MDI Open we can notice that the main menu of the MDI Form is replaced with theMenu of the
Child Form.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 96
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

UNIT – V
Introduction to Database - Working with Data Control: The Data Control - The Bound Control – Coding
– Data Access Object: Functions of the Jet Database Engine – The DAO Object Model - Crystal and
Data Reports: Crystal Report - Data Report – Creating Multiple Reports

INTRODUCTION TO DATABASE
Definitions:
Database
"A set of data related to a particular topic or purpose. A database contains tables and can also
contain queries and table relationships, as well as table and column validationcriteria."
Table
"A table is a collection of data, arranged in rows and columns. For example, you might have a
table for author information called authors. Each column would contain a certain type of
information, such as the author's last name. Each row would contain all the information about a
specific author: first name, last name, address, and so on."
Recordset
A recordset is an object that contains a set of records from the database. There are mainly five
types of Recordset object.
1. Table-Type Recordset: The table type recordset object is a set of records that
represents a single table can be used to add, change or delete records. They are
fastest type of Recordset.
2. Dynaset-Type Recordset: The dynaset-type recordset object is a set of records
that represent a table, or attachment tables, or the results of queries containing
fields from one or more tables. A dynaset enables us to update data from more
than one table.
3. Snapshot-Type Recordset: the snapshot type recordset can refer any table,
attached table or query. A snapshot cannot be updated and does not reflect
changes to data made by the users.
4. Dynamic type Recordset: This recordset type represent a query result set from
one or more base tables in which we can add, change or delete records from a row
returning query. Further, records that other users add, delete, or edit in the base
tables also appear in our recordset. This type is only available in ODBCDirect
workspace, and corresponds to an ODBC dynamic cursor.
5. Forward Only Type recordset: This recordset type is identical to a snapshot
except that we can only scroll forward through its records. This improves
performance in situations where only need to make a single pass through a result
set. In an ODBCDirect workspace, this type corresponds to an ODBC forward-
only cursor.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 97
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

VB Data Control:
VB provides two controls which makes the link to the database file and which creates the recordset that
is exposed to the rest of the controls in your application. The two are identical in concept but differ in the
flexibilty they offer to the programmer.
1. Data control:
This is the original, intrinsic version of the control. It supports the JET database engine and can
satisfy most beginners' needs.
2. ADO Data control:
This is the latest version of the data control, implemented as an ActiveX control.

WORKING WITH DATA CONTROL: THE DATA CONTROL


1. Create a database using MSAccess, Oracle or Sql server named st_detail and a table
2. Student table having fields (name, roll no, class).
3. Start a new Standard EXE project and design a Form that looks like

4. Start by drawing a Data control at the bottom of the Form. The Data control is your
gateway to the database.
5. With the Data control selected, locate its DatabaseName property, and set the path to
st_detail database.
6. Locate the RecordSource property in the Properties window, and drop down the list of
available entries. You‘ll see a list of all the tables in the st_detail database. Select the
student table.
7. Place three textboxes on the Form.
8. Select the first textbox, and in the Properties window locate its DataSource property. Set
it to Data1.
9. Set the DataField property of the textbox to Name. The DataField property is a drop-
down list with the names of all fields in the student table.
10. Set the DataSource property of the other textboxes to Data1, and set the DataField
property to Roll No, and Class.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 98
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Now run the application. The textboxes will display the values of the corresponding fields of the student
table. Using the Data control‘s buttons, you can move through the records (rows) of the table. Clicking
the leftmost button displays the first record of the table, and clicking the button next to it displays the
previous record. Clicking the rightmost button displays the last record of the table, and clicking the
button next to it displays the next record.

THE BOUND CONTROL


The Data-Bound Controls: You can bind certain controls to the data control, the remote data control,
and the ADO data control, and those controls are called bound controls. To bind a control to a database
control, you use properties like DataSource to specify the database control, and then use properties like
DataField or BoundColumn to specify what field to display in the bound control, as we‘ll see. Here are
the controls that can function as bound controls:

• Picture boxes
• Labels
• Text boxes
• Checkboxes
• Image controls
• OLE controls
• List boxes
• Masked edit controls
• Rich text boxes
• Combo boxes

In addition, there are special controls that are designed to be used as bound controls:
• DBList
• DBCombo
• FlexGrid
• MSFlexGrid

Finally, a number of bound controls are specially built to be used with the ADO control only:
• DataList
• DataCombo
• DataGrid

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 99
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

DATA ACCESS OBJECT: FUNCTIONS OF THE JET DATABASE ENGINE


 DAO (Data Access Objects) is an application program interface (API) available with Microsoft's
Visual Basic that lets a programmer request access to a Microsoft Access database. DAO was
Microsoft's first object-oriented interface with databases.
 Previous versions of VB used the Data Access Object Control: DAO.
 DAO is/was particularly good for MSAccess and MS-SQL-Server databases.
 DAO has limitations in dealing with nonMicrosoft databases.
DAO connections:

DAO objects encapsulate Access's Jet functions. Through Jet functions, it can also access other Structured
Query Language (SQL) databases.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 100
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

Objects in DAO object model


The following are the various objects in DAO object model.

Each object contains collections, methods and properties.


1. A collection is a collection of objects of the same type.
2. A method performs an operation on the object.
3. A property contains a single attribute of the object.

The DBEngine is the highest-level object in the DAO object model. It contains all other objects and
collections. The Database object is the member of the Databases collection of the default Workspace
object, which is a member of the Workspaces collection of the DBEngine object.

With DAO, objects you use to work with the data in the database are generally not saved but are created
every time you need them. Objects that represent the structure of the database are saved with the database.
When you create a new DAO object to be saved in the database, you have to append it to the appropriate
collection using the collection's Append method. Keep in mind that all DAO objects are indexed
beginning with zero.

DAO lets you work with three database formats:


Microsoft Jet (all databases that are created with the Microsoft Jet database engine)
Installable ISAM format
ODBC data sources

Jet and ISAM data use the Microsoft Jet object model; however, with ODBC data, you can use either
Microsoft Jet or ODBCDirect. There are some limitations in accessing ODBC data using Jet, although
you can use it if you need to take advantage of a particular Jet feature. But ODBCDirect is more flexible,
allowing you to run queries or stored procedures against the backend server and perform batch updates
and asynchronous queries. It also makes your application run faster because it allows you to bypass
Microsoft Jet's middle layer.

What is Jet Engine?


 Jet Engine is the database engine that accesses the data. Jet Engine is a collection of programs
that work together. Jet Engine makes use of some other translators to access various types of

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 101
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

databases. Each type of database such as dBase, FoxPro, and Paradox etc has its own translator.
These translators are to be available to access the particular type of database.
 Jet Engine can also access ODBC data sources using ODBC drivers.
 Jet Engine also has its own query engine, which is used to search, order and filter the data without
using the query engine of the database. This may be an advantage with small databases such as
MS-Access and FoxPro, but for large databases such as Oracle database, using Jet query engine
may be inefficient.
 Also remember DAO and Jet Engine are not designed for Internet or Intranet. To access data in
either
 Internet or Intranet use ADO (ActiveX data objects) with OLE DB.

DAO with Jet


Microsoft Jet objects
include TableDef, QueryDef, Field, Index, Parameter, Relation, Recordset, User, Group, Container,
and Document.

The DBEngine object contains two collections: Workspaces and Errors. The Workspaces collection is the
default collection of the DBEngine, so you don't have to refer to it explicitly. When you don't specifically
create a new Workspace object, DAO will create one for you. The setting of the DefaultType property of
DBEngine determines what type of workspace is created for Microsoft Jet or ODBCDirect. The default
value of this property is dbUseJet, but you can explicitly set it to dbUseODBC as the type argument of the
CreateWorkspace method.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 102
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

The Workspace object defines a session for a user based on users' permissions and allows managing of
the current session. It also contains open databases and offers mechanisms for simultaneous transactions
and for securing the application. The Fields collection is the default collection for TableDef, QueryDef,
Index, Relation, and Recordset objects. Recordset objects can be of the following types: Table, Dynaset,
Snapshot, or Forward-Only.

Crystal and data reports


1. Crystal Report
 Create a new report by choosing File menu - New and the Create New Report dialog box will appear
(see picture below)

 Click on the Custom button to display the Choose Report Type and Data Type frames.
 Select the Custom Report and click on the Data File.
 Specify the location of the BIBLIO.MDB Access database.
 Select which tables from the database you want. For this example we will need the authors table
and the Title table.
 Check that the joins are correct in the Linking Export.
 Now we are ready to draw the report.
 Drag and drop the fields you want on to the report. So that it looks like the report above.
 Now if you run it by selecting Print Preview, you can see what the report looks like.
 Now save the report and we have a template that now can be used in VB.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 103
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

There are many options in the Crystal Reports and as this tutorial is more of an overview I will not be going
into it. But one important thing to do is to get specific data. This is done by a selection formula (i.e. the Where
clause of a SQL statement).

The above formula will only show Authors that have had their book published in 1984.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 104
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

2. Data Reports
 We can create a Data Report. We will drag things out of the Data Environment onto a form
created for the Data Report, so make sure your Data Environment window is still available.
 On the Project menu, click Add Data Report and one will be added to your project. If this item is
not on the menu, click Components. Click the Designers tab, and choose Data Report and click
OK to add the designer to your menu.
 Set the following properties for the report:
Name: rptPhone
Caption - Phone Directory
DataSource - denPhone (your phone data environment - choose, don‘t type)
DataMember - PhoneList (the table name - choose don‘t type)
 Right-click the Data Report and click Retrieve Structure. This establishes a report format based on the
Data Environment.
 Note there are five sections to the data report: a Report Header, a Page Header, a Detail section, a Page
Footer, and a Report Footer. The headers and footers contain information you want printed in the report
and on each page. To place information in one of these regions, right-click the selected region, click Add
Control, then choose the control you wish to place. These controls are called data report controls and
properties are established just like you do for usual controls. Try adding some headers.
 The Detail section is used to layout the information you want printed for each record in your database.
We will place two field listings (Name, Phone) there. Click on the Name tab in the Data Environment
window and drag it to the Detail section of the Data Report. Two items should appear: a text box Name
and a text box Name (PhoneList). The first text box is heading information. Move this text box into the
Page Header section. The second text box is the actual value for Name from the PhoneList table. Line this
text box up under the Name header. Now, drag the Phone tab from the Data Environment to the Data
Report. Adjust the text boxes in the same manner. Our data report will have page headers Name and
Phone. Under these headers, these fields for each record in our database will be displayed. When done,
the form should look something like this:

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 105
ASSISTANT PROFESSOR OF CS
SEM: V CLASS: III-B.Com.CA
SOFTWARE DEVELOPMENT WITH VISUAL PROGRAMMING

 In this form, I‘ve resized the labels a bit and added a Report Header. Also, make sure you close
up the Detail section to a single line. Any space left in this section will be inserted after each
entry.
 Click File and Save rptPhone As. Save the environment in an appropriate folder. We will now
reopen our phone database manager and attach this and the data environment to that project and
add capabilities to display the report.
Accessing the Data Report
 Reopen the phone directory project. Add a command button named cmdReport and give it a Caption of
Show Report. (There may be two tabs in your toolbox, one named General and one named DataReport.
Make sure you select from the General tools.)
 We will now add the data environment and data report files to the project. Click the Project menu item,
then click Add File. Choose denPhone and click OK. Also add rptPhone. Look at your Project Window.
Those files should be listed under Designers.
 Use this code in cmdReport_Click:
 Private Sub cmdReport_Click()
rptPhone.Show
End Sub
 This uses the Show method to display the data report.
 Save the application and run it. Click the Show Report button and this should appear:

3. Multiple Report
To create a report
 In Visual Studio, create or open a Report Server project. For more information, see Create a
Report Server Project for Visual Studio ALM.
 On the Project menu, choose Add New Item.
o The Add New Item dialog box appears.
 Choose Report Wizard, and then choose Add.
o The Report Wizard opens to the Select Data Source page.
 Choose the Tfs2010OlapReportDS shared data source, and then choose Next.
o Even though you might have installed or upgraded to TFS 2013, these names, which were
assigned to the data sources for TFS 2010 are in use.

Mrs.S.PUNITHAVALLI.,MSc.SC(DA)., 106
ASSISTANT PROFESSOR OF CS

You might also like