Professional Documents
Culture Documents
Visual basic
Unit 1:
Introduction:
Visual basic is a integrated development environment which is used to create an application as
an windows based one
Every visual basic has different type of application normally you can create standard.EXE
application to create a windows application.
You can also use ActiveX control to create based standard control. There are 2 different types of
standard.EXE available. They are 1. Single document interface (SDI), 2. Multiple document
interface (MDI).
Title bar:
Title bar is a horizontal bar located at the top of every window. It gives the name of the
application in the windows application. EX. If you having the multi task between two windows
application like the Ms Paint & Ms Word file you can choose the application based on the title
of each application.
Menu bar:
Menu bars are used to interact with the particular windows application. If you need to create an
application you can choose file menu. It also used to save the file, close the file etc.
Tool bar:
Tool bars are used as a shortcut keys or direct usage keys for the menu bars. All the tool bars
will be displayed with their icons inclusive with home some icons are standard tool bar in VB.
B.Balaji (b.balag@gmail.com)
Page 2 of 62
ADD Standard.EXE:
Whenever you clock this icon, it will create a new executable visual basic file.
ADD form:
IT is used to add a new form to your application or project.
Open project:
It is used to open an existing visual basic project.
Start:
It is used to run the current application. You can also use run menu and start button.
Break:
It is used to pass the running project.
End:
It ends the running project.
Project Explorer:
It is used to visible the project explorer window inside the current application or if you are
pressing the project explorer the focus will be moved to project explorer window.
Property window:
It is used to visible the project explorer window.
Tool box:
It enables the tool box window inside the application.
B.Balaji (b.balag@gmail.com)
Page 3 of 62
Project Explorer:
Project Explorer are used to display the available project(programs) and different types of
available forms in current application. Every project explorer is used to switch the control from
design window to code module window. Using the project explorer you can add new form to
the current object and you can also sort the forms by ascending or descending order. There are
3 different tools available in project explorer.
1. View code:
2. View Object:
It is used to display the current design module.
3. Folders:
It is used to view or hide the available forms inside the project.
4. Project property:
It is used to setup the startup form and you can also rename the project names, project
description and make of the project.
5. Single precision
6. Double precision
B.Balaji (b.balag@gmail.com)
Page 4 of 62
You can declare an integer value by ’%’ symbol at the end of the each variable names.
Eg:
Variable name %
A%
Eg:
Variable name&
A&
Eg.
DOB=#01dec2012#
IND@=24.00
B.Balaji (b.balag@gmail.com)
Page 5 of 62
You can also simply declare a variable without any data type and it will be known as variant data type.
SYNTAX:
Dim a as variant
(Or)
Dim a
SYNTAX:
Dim a as string
(Or)
A&
Declaring variable:
All the variables must be declared with the keyword dim (dimensional) of the keyword. This indicates
each variable must be declared with this keyword. You can declare the variables anywhere inside the
code module in VB application.
Eg:
In every objects form is the basic window which is used to creating an application.
A form is a window that contains application code and objects which is used to create the user interface.
B.Balaji (b.balag@gmail.com)
Page 6 of 62
Every form cans different type of standard controls or dialog boxes which can change the form interface.
Properties in forms:
Generally forms have basic common properties and some special properties inside Visual basic. Each
and every property has the unique way of approach.
Naming property:
Name property defines the current form name which is used to refer the form properties, events and
methods inside the application.
Caption property:
Caption property is used to enable the change inside the current form title.
Color property:
Color property consists of 2 types 1. Fore color, 2. Back color.
Fore color is nothing but the displaying the text color in the current window.
Back color is color displayed at the background of the current window.
Appearance property:
Determines whether the form needs to be in 3 dimensional look. The default value for appearance is 1.
If you change the value to 0 the form will appear as flat display.
B.Balaji (b.balag@gmail.com)
Page 7 of 62
Enable property:
Enable property is used to respect the events such as form click event, focus events, key events, mouse
events and etc.
If you set the property enable to false the form cannot respond to any about events.
Visible property:
Visible property is a dangerous property which is used to display the execution of each and every
position of the form. If you set the value of visible false the form will be not visible to the user during run
time.
Form1.width=1000
Form1.height=2000
End sub
Form1.move 500000
End sub
Form1.window state=2
End sub
Hscroll1.value=1000
Vscroll1.value=1000
B.Balaji (b.balag@gmail.com)
Page 8 of 62
End sub
End sub
End or load me
End sub
Scale Properties:
Scale properties are used to display the form with different size according to the monitor display.
Scale mode
Scale mode are used to change the units of internal coordinated of the forms inside the system.
This uses pixel centimeters or inches or multi meters unit of resolution to change the scale
mode in monitors.
Scale height and scale width:
This type of property is used to setup scale height and width of the forms from scale mode
property.
Scale left and scale top:
This type property describes the changes of scale left and scale top of the form inside the
monitor.
Font property:
This Property used to set the front text values. You can use font type, font style, font size,
underline and strike through.
B.Balaji (b.balag@gmail.com)
Page 9 of 62
Events in form:
Events are the procedures used execute code modules.
Coding . . .
End sub
Load event:
This event will be fired when a form is loaded for first time.
Syntax:
Private sub form1_load()
Coding . . .
End sub
By default form loads are for initializing for the values, standard controls and events procedures
for every form load this event will be fired only once.
Resize() Events:
This event will be fired whenever a form is resizing. That means you can repaint the user
controls inside the forms.
Click() Event:
This event will be fired when the mouse pointer clicked inside the current form.
Double click() event:
This event will fired when the mouse button is clicked twice.
SYNTAX:
Private sub formname_dblclick()
Coding
End sub
Text box control are used to accept the values from the user as a input to any variable
Text box are used to display the values as a output to the user.
Generally text box accept the value from the user as a string data type. We need to change the string
data type we need to change the string value to a integer using val() function.
B.Balaji (b.balag@gmail.com)
Page 10 of 62
TEXT:
Text property are used to get the value from the user and assign to a variable as controls this
also used to set the value for the output to the user.
The default value for every text box is text number.
Alignment property:
This property controls how the text should be displayed. The default value is 0(left alignment). If you
change the value to 1, the text will be right aligned if the value is 2 the text is centered.
Multiline property:
This property determines whether a text box can accept more than one line of text. This control is a
Boolean control if you enable the multiline option VB automatically enables wordwrap. The multiline
property fo text box with accept 32000 characters.
Scroll bars:
This property enables when multilevel property is enabled. You can choose two type of scroll bars
horizontal scroll bar if the value is 1. The text box will have only horizontal scroll bar and it will limit the
character. If the value is 2 the text box has vertical scroll bar only.
Max length:
This property determines the maximum no. of character to the text box. The default value is 0. (i.e.)
32000 character any setting other than 0. Will limit the user to change no. of character.
Password character:
Password character property lets you to limit what the text box displays when the password is entered.
By default the password char users ‘#’ symbol.
Border style:
Border style are used to possible settings for the text box. The default value is 1 which gives you a single
width border. If you change the property to 0. The border will be disappeared.
Locked:
It is a Boolean property which is used to prevent users from changing the content of the text box.
B.Balaji (b.balag@gmail.com)
Page 11 of 62
Event procedures:
Text box can recognize 23 event procedures.
Ex:
Text1.text=”welcome to VB”
Text3.text=”thank you”
End sub
End sub
End sub
End sub
End sub
B.Balaji (b.balag@gmail.com)
Page 12 of 62
Change event:
Change event are used to executive a code module whenever text box need to change in run time.
SYNTAX:
Coding----
End sub
Key events:
There are 3 different types of key events in a text box 1. key down, 2. Key up, 3. Key press.
Key down:
This event will be executed whenever the user pressing any keys inside the keyboards.
Key up:
This is event will be fixed whenever the user releases the keys in a keyboard.
Key press:
This event has the similar features like key down event.
General syntax:
{key press
Key down
Key up}
Coding---
End sub
Labels:
Labels are used to display information to the users at the runtime. The most common use of labels are
to identify a text box or any other standard controls. Labels have 34 possible properties. Yo u can use 30
properties at design window itself.
B.Balaji (b.balag@gmail.com)
Page 13 of 62
Caption property:
Caption property are used to display the text as a description as a label control.
Align property:
Alignment property for label has 3 possible settings. Default it will be in left alignment and the values is
0. If the value is 1 the alignment will be right justify. If the value is 2. The best will be centered.
Command button:
Command button are the most useful controls inside a VB application all the application must have
atleast one command button inside each form.
Caption:
Caption properties on a command properties determines the user what to be seen as a text in command
you can use any text for a caption property on a command button is automatically centered with in the
button.
Enable:
This property determines whenever the button can respond to any events are not. If you set the
property to false no events will not respond to the button.
B.Balaji (b.balag@gmail.com)
Page 14 of 62
Visible:
Determines whether the command button is visible to user or not. If the property is false the command
button will not be displayed at run time.
Mouse pointer:
Mouse pointer are useful when the mouse cursor changes when you enter inside the command button.
You can change the mouse cursor icon using the mouse pointer property.
Picture property:
Picture property are used to set a picture inside a command button instead of caption property. To
display a picture you need to set a style property in a command button.
Style property:
Style property are used to set a special appearance to a command button by default style property will
be in 0 that means the command button is in standard format if you change the style property to 1. The
command button will be in graphical style.
Down picture:
Down pictures are used to set the pictures when an command button is fixed.
Disabled pictures:
Disabled pictures property are used when an command button is set to an enabled false.
Command button supports special event procedures like mouse events and keyboard events.
Mouse events:
Command button supports 5 different types of mouse events.
B.Balaji (b.balag@gmail.com)
Page 15 of 62
End sub
Label5.caption=”total of a*b”
Text1.text=””
Text2.text=””
Text3.text=””
End sub
A=val(text1.text)
End sub
B=val(text2.text)
End sub
C=a+b
Text3.text=c
End sub
B.Balaji (b.balag@gmail.com)
Page 16 of 62
Access keys:
Access keys are used to create a shortcut buttons for any objects inside the VB application. Generally
access keys are used for creating a short cut for menu bars, command buttons, check box, radio button
and etc.
Every access keys can be controlled using & symbol in the front of any character in your caption
property.
Many windows application allow to pressing alt key + some combination keys to activate general
windows shortcut. You can use a control keys and alter keys with addition of any other keys
combination to access the combination key.
Message boxes:
Message boxes used to display a information in a dialog box on a form this message boxes will want for
the users to return the choice button before executing the application. The users cannot switch to any
other application without responding to the message box.
VB OK CANCEL 1 It will display ok and cancel buttons inside the message box
VB ABORT RETRY IGNORE 2 It will display abort, retry, ignore buttons inside message box
VB YES NO CANCEL 3 It will displays yes, no, cancel inside message box
VB RETRY CANCEL 5 It will display retry and cancel button inside message box
VB CRITICAL 16 It will displays a critical msg icon before the msg in msg box
VB QUESTION 32 It will displays a warning icon before the msg in msg box
VB EXCLAMATION 48 It will displays a warning msg icon before the msg in msg box
VB INFORMATION 64 It will displays a information msg icon before the msg in msgbox
B.Balaji (b.balag@gmail.com)
Page 17 of 62
VB DEFAULT BUTTON2 256 The second button in the msg box will be default
VB DEFAULT BUTTON3 512 Third button in the msg box will be default
EXAMPLE:
Input box:
Input box functions to get the value from the users at run time and it will be return to a variable
declared. Generally all input box will be displayed like a dialog box at run time.
Prompt:
Prompt parameters is a string variable 29 any text values which is to be displayed as a caption in input
box all the captions can be not exceeded than 1024 characters. in input box all the captions can be not
exceeded than 1024 characters.
Title:
Title parameter is a optional and it will gives the caption used for the title bar in the input box. By
default the application name or program name Is been used as a title bar.
Default parameter:
It is a optional parameter which is used to give a default value to the text box available inside the input
box.
Helpfile:
It is used to give each descriptions about the context used inside the input box.
B.Balaji (b.balag@gmail.com)
Page 18 of 62
End sub
C=a+b;
End sub
Text1.text=””
Text1.text=c
End sube
Unit-2
DEFAULT SYNTAX:
Print values
Font method:
Font method are used to change the style of the standard controls inside any forms using the font
method all the changes will be occur at run time only.
SYNTAX:
Objname.font.size=value
Objname.font.style=type
B.Balaji (b.balag@gmail.com)
Page 19 of 62
SYNTAX:
Formname.currentx=value
Formname.currenty=value
There are 6 types of events which will be loaded whenever a form is been loaded for first time. This
events will be executed without the user interface.
1. Form_initialize()
2. Fomr_load()
3. Form-resize()
4. Form_activate()
5. Form_gotfocus()
6. Form_paint()
Form-initialize():
This event is triggered first and only once normally initialize event occurs before the load event is fired
by you cant to add or remove any control means you can place code in initiliaze event.
Form_load():
This event is triggered is load or enter the inputs into the user variable.
Form_resize():
Form resize event is fired whenever the user resizing a form or minimizing a form and then restarting
the form before starting the program. Generally form resize event are used to recalculation the size and
Form_activate:
This event will be fired whenever a form is been loaded before anyother forms inside multidocument
interface. This type of event is used only in multiple form application.
B.Balaji (b.balag@gmail.com)
Page 20 of 62
Form_gotfocus:
Gotfocus event will be triggered whenever a form is been loaded and all standard controls are disable.
Form_paint:
Paint event are used to add a paint method a form needs to display a text you can use this event
procedures to redraw the informations on the form. To utilize this paint event you need to set the auto
redraw property to true. So this event will be automatically display the print method property.
Print”hello”
End sub
Print”resize event”
End sub
Print”paint event”
End sub
Paint”activate event”
End sub
Print”initialize event”
End sub
B.Balaji (b.balag@gmail.com)
Page 21 of 62
End sub
cls
End sub
end
End sub
Refresh method:
Refresh method are used to order forms available in multi document interface. You can also use refresh
method to redraw the print event procedures. To rewrite the print method.
Syntax:
Formname_refresh
Show method:
Show method are used to display the form in current window you can add the show method in any
standard control. Current form will be overloaded by the new form.
Syntax:
Formname.show
Hide method:
Hide method are used to display the visible of current window from the current application.
B.Balaji (b.balag@gmail.com)
Page 22 of 62
Syntax:
Formname.hide
Syntax:
Print format(…)
Name Description
General date it displayed a date and time available inside the system. By default it will
Long date it display the date format inside the windows include day, month and year.
Long time it displays the current time of the windows with inclusive of hours, minutes, seconds
in 12 hours format.
Medium time it displays the current time of the windows with hours and minutes in 12 hours format.
Me.font.size=12
Me.print.format(now,”long date”)
Me.print.format(now,”medium date”)
B.Balaji (b.balag@gmail.com)
Page 23 of 62
Me.print.fomrat(now,”short date”)
Me.print.format(now,”long time”)
me.print.format(now,”,medium time”)
me.print.format(now,”short time”)
end sub
design window:
11/1/95 11:08:46pm
01-nov-95
11:08:47pm
11:08pm
23:08
Cls
Left=me.scale width/2
Top=me.scale height/2
B.Balaji (b.balag@gmail.com)
Page 24 of 62
Top=me.scale top+top
Print message
End sub
Rich text box control does not have any limits to the text.
Rich text box are the custom controls which you can import from the components window. To add a rich
text box you can use two different methods.
1. Choose project_components
2. It will open a component dialog box
3. Then click Microsoft rich text box control 6.0
4. 2. Right click on the tool box.
5. Then click on components it will open the components dialog box or you can press ctrl+t for
components dialog box.
Properties:
Rich text box has the same properties like text box control. There are same different properties used to
select, used to cut, copy and paste the text.
Selstart it used to set or return the starting point of selected text in rich text box.
Sellength it is used to set or return the no. of characters selected in rich text box
B.Balaji (b.balag@gmail.com)
Page 25 of 62
Selstrikethree it is used to set a strike three line for the selected text.
Selcolor this property sets the color for the currently selected text. You can use text
Set font name this property is used to change the font style for the slected text.
Setfont size this property is used to change the size of the font for currently selected text.
Message=”you can select text after you type in the box and”
Message=message&”then click on one of the buttons to see the changes go into effect”.
End sub
End sub
End sub
End sub
B.Balaji (b.balag@gmail.com)
Page 26 of 62
End sub
End sub
DESIGN WINDOW:
CHAPTER-2
Determinate loops:
Determinate loops are used to define the flow of the control inside the procedures. This is type
of looping are used for testing the value for and users for some conditions. This type users for some
conditions. This type of loops are of three types.
1) For statement,
2) For next statement,
3) Nested for statement.
For statement:
This type of looping statements are used to generate control structure which used to operate a
block of statement. This determine the startin and ending value.
B.Balaji (b.balag@gmail.com)
Page 27 of 62
1) for keyword:
this are used to set the starttin value and the ending value for the variable.
2) Next keyword:
This are used to define the increment for variable by default, next keyword used as a increment
operator.
---------
eg:
for i=1 to 10
print i
next i
B.Balaji (b.balag@gmail.com)
Page 28 of 62
6) If the step keyword have been included the next keyword look the step value whether to
increment or decrement counter variable.
7) The step keyword are used to change the counter variable by one variable by any number will
accept positive or negative.
Eg:
Dim I as integer
Print i
Next i>3
-----------
Example:
Dim i,j,k
End sub
I=val(text1.text)
J=val(text2.text)
B.Balaji (b.balag@gmail.com)
Page 29 of 62
Print k
Next k
End sub
For i=1 to 5
Next j
Next i
End sub
Print k
Next k
End sub
Indeterminate loop:
Interdeterminate loop consist of 3 types:
1) Do while loop
2) Do until loop
3) While/went statements
Do while loop:
This is executed with differen types of relational operators and logical operators. This type
statements will be executed once, the condition will be checked for the logical operators. If the
condition has been statisfied, the loop will be executed else the condition will be executed.
B.Balaji (b.balag@gmail.com)
Page 30 of 62
Default syntax:
Do
Statements
--------
-------
Eg:
Dim x
Do
Print x
End sub
Do until loop:
This are used to find the exact matching value for the given condition. You can use only assignment
operator inside the do until condition.
Syntax:
Do
statements
--------------
--------------
Eg:
Dim x
B.Balaji (b.balag@gmail.com)
Page 31 of 62
Do
Print x
End sub
Syntax:
Do
Statements
-----------
Statements
---------
Wend
Eg:
Dim a
Do
A=val(inputbox(“enter value”)
Print=”only once”
Print a
Wend
B.Balaji (b.balag@gmail.com)
Page 32 of 62
End sub
1) If then statements
2) If then else statements
3) Nested if statements
4) Select case or select statement
If then statement:
This are single line decision making statement you can use this type of statements without using end if
keyword.
Syntax :
If (condition) then statement
Or
End if
Syntax:
If (condition) then
Statement
Else
Statement
End if
B.Balaji (b.balag@gmail.com)
Page 33 of 62
Nested if statement:
This is also known as block if then statement. You can have n no. of if condition but you need to exactly
close the else part for each if then statement.
Syntax:
If (condition) then
If (condition) then
Statement
Else
Statement
Else
Statement
End if
End if
Eg:
If x>1 then
If x>5 then
Else
Print “x is between 1 to 5”
Else
End if
End if
End sub
Dim x
B.Balaji (b.balag@gmail.com)
Page 34 of 62
Print x
End sub
Syntax:
Select case variable
Case value 1
Statements
Case value 2
Statements
Case else
Statements
End select
Eg:
t=0
If op = 1 Then
Text2.Text = Text1.Text
op = 0
Else
B.Balaji (b.balag@gmail.com)
Page 35 of 62
Select Case s
Case "+"
Case "-"
Case "*"
Case "/"
End Select
End If
s = Command2(Index).Caption
f=1
End Sub
t=0
If s = "+" Then
Else
End If
op = 1
B.Balaji (b.balag@gmail.com)
Page 36 of 62
f=1
End Sub
Goto statement:
This are used to pause the current statements to any other states inside the form. This type of
statements are used to jump the control from one place to another place without executing the next
line statements.
Syntax:
Line variable:
---------
--------
Line variable:
-----------
Eg:
Dim i As Integer
Dim j As Integer
Dim k, l As Integer
first:
Text1 = i
If (i < 0) Then
MsgBox "enter only positive integers", vbInformation + vbOKOnly + vbDefaultButton1, "integers only"
GoTo first:
End If
Control arrays:
B.Balaji (b.balag@gmail.com)
Page 37 of 62
This are used as a special control which are designed in vb to used standard control as array. You can use
standard controls such as command button, check box, option box, list box etc..,
Every control has its own control array by pressing control + copy in design time & porting the same
control inside the design window. By default vb will appear a pop up message adding you need to have a
control array for the control or not.
Arrays:
The fundamental structure of organizing the information inside to a variables are known as arrays.
Generally, the arrays are have different types of dimensions.
Syntax:
Dim variable [index value] as data type
Int a[10]
Eg:
Dim a[5], i
Print a[i]
Next i
End sub
a*0+=”2nd bca”
B.Balaji (b.balag@gmail.com)
Page 38 of 62
a*1+=”welcome”
a*2+=”vb lab”
a*3+=”array”
a*4+=”example”
a*5+=”thank u”
end sub
fixed arrays:
this are used to hold the memory space of the array values, throughout the application then memory
will be exited when program has closed.
Dynamic arrays:
This are used to change the size of index value while, executing each control. The memory allotment will
be changed according to the execution of the program.
Syntax:
Dim variable[index1], [index2] as data type
Eg:
Dim i, j
For i=1 to 12
For j=1 to 12
Next j
B.Balaji (b.balag@gmail.com)
Page 39 of 62
Next i
End sub
Functions is a block of statement which can be defined by user. This set of code can able to function
throughout the application.
All the function can able to return value to a calling function name. the return type can be vary
depending upon the data type.
-----------
------------
End function
1) Private
2) Public
3) Static
You can declare the function, anywhere inside the code module. You need to specify the return data
type, if you are position an arguments. The return type data types can differ for the function procedures.
You can add the function using built-In functions dialog box.
You can also open this ass procedure by pressing a shortcut all+f or f>.
Procedures:
A procedures is a set of block which can execute the user defined coding, according to the calling
B.Balaji (b.balag@gmail.com)
Page 40 of 62
Function name. generally, procedures will not return any value for the calling procedure name.
procedures allows you to move program or will allow to change the logic from one place to another
procedures are used in one program can be used to a logic for another form.
Types of procedures:
1) Sub procedures
2) Function procedure
3) Property procedure
Sub procedures:
This are the difficult procedures type. This are by default has a specific module which are used to
execute and pass the value to entire application.
Syntax:
[private] [public] [static] sub procedures name (arguments)
----------------
------------------
End sub
General procedures:
It is used to define your own sub procedures. It is used to perform different types fo task. Once it
procedure name is involed. By default, all general procedures can be written in any type of public forms.
You can also include the general procedures inside class module application. You can also use a general
procedure to pass the value to the local variable inside procedure name.
Syntax:
Syntax is as similar as sub-procedure.
B.Balaji (b.balag@gmail.com)
Page 41 of 62
Event procedure:
Every vb application, must have a single event procedures. All the application which are running while
the project is executing event procedures are called as an object in visual basic. All the standard controls
inside the vb, having the event procedures.
Syntax:
Private sub controlname_eventname()
----------------
----------------
End sub
Property procedure:
This are used like function procedures or sub-procedures. It is used to invoke the changes for the
current controls, properties at run time. you can change the different type of properties while running
the application, without changing in design time can also add the return type for the calling property
procedures.
Syntax:
[private] [public] [static] controlname_property name()arguments) as datatype
----------
----------
End sub
Eg:
Dim s
S=caption
Print s
Command1.caption=s
Sub end
B.Balaji (b.balag@gmail.com)
Page 42 of 62
Command1.caption=”second bca”
End sub
Unit – 3
It is a built-in pop up dialog box, which is used to enable different type of actions durinf the execution of
an application. You can add different type of events to a menu editors, such as click event, got focus
event etc..,.
A menu is a first and fore most ordinary pop-up window, which is used to respond,
mouse events and key board events. You can also use a access key to enable the short cut for the menus
inside the form.
To add a menu editor, you need to enable the menus, inside the form.
You can add a menu editor using a menus called toole-menu editor or you can use control+e as shortcut
key for menu editor.
After adding the menu editor, the menu editor is open with different properties like,
caption, name, index box, enable text, visible check box, arrow buttons, next button, insert and delete
button.
Caption property:
This are like caption text box property. It is used to add the caption for menus which will be
displayed as the default label for menu.
Name property:
This are like name text box property. It is used to name the current menu which can be used for any
event procedures with the control name. if you are using the same menu, more than once, you can
name the current name with index properties.
B.Balaji (b.balag@gmail.com)
Page 43 of 62
Shortcut box:
It is used to add a shortcut for the current menus. By default of keys, which can be added as a list box
inside the shortcut box. You can cannot use a alt+f4 shortcut for the menus.
Arrow buttons:
This are used to highlight the menu items which menu and sub-menu. you can use four types of arrow
buttons to utilize the menu options hierarchy. You can also create ‘n’ no. of sub-menus, hierarchical to
the default menu items.
Next buttons:
Using this property, you can move the menu item to next main menu.
Insert buttons:
It is used to finalise the current menu item.
Delete item:
It is used to remove the currently highlighted menu items.
Multi-document interface:
It allows to create an application that can maintain multiple forms with a single contains forms. Best
example for multi-document interface is Microsoft excel.
B.Balaji (b.balag@gmail.com)
Page 44 of 62
Un Loading forms:
This will be works when you are closing the mdi form. If you are closing a child form, it does not
mean mdi form will be unloaded. If the user closes the application inside an mdi form, The entire
applications will be unloaded.
example: mdi coding
Form1.show
End sub
Form2.show
End sub
End sub
Form1:
End
End sub
B.Balaji (b.balag@gmail.com)
Page 45 of 62
Form2:
End
End sub
Error trapping:
Error trapping are used to prevent a error inside any applications. You can use a command, that
activates this type of errors, within a procedure or functions, it can be denoted by error go to label or
error line no. the label represents the current procedures or events which is having the error, will be
directly moved to the command, which throws the error message once you started error trapping within
the error go to command the run time error will not displayed for the application.
Syntax:
on error go to label(trap)
----------
----------
Error label=(trapping)
Err code
Resume statement:
For example, if an error occurs while running a program. On error go to command will be executed
automatically after display the error the program can resume using the resume statement inside the
function procedures.
B.Balaji (b.balag@gmail.com)
Page 46 of 62
If you are using the error method, it will return a variable value, which can be used to display the error
methods or error names. By default, vb can identify 60 run time errors. You can able to find out capable
errors inside the vb using err object.
483 it is used to display the error, when the printer device is not
supported.
Variable=err object
Eg:
Dim a
A=errorcode 57
Text1.text=a
End sub
B.Balaji (b.balag@gmail.com)
Page 47 of 62
Syntax:
Err.clear
If you are using error go to statement, you need to reset the statement with 0. It can be denoted by an
error go to 0.
Error number=err.number
Case 57
Case 68
Case 482.483
M$ =m$. & “a general printer error with” & error number & “occurred”
Msgbox m$
End
Case else
Msgbox m$
B.Balaji (b.balag@gmail.com)
Page 48 of 62
End
End select
End sub
1) click event
2) double click event
there are five more special mouse events which are used in vb are:
Syntax:
Object name_mousedown (or) mouseup (or) mousemove( button as integer, shift as integer, x as single,
y as single)
-------------------
End sub
Mouse up event:
This event will be executed, whenever mouse button is released from the control or form. It has the
similar features for buttons.
B.Balaji (b.balag@gmail.com)
Page 49 of 62
Since the user does not require to press any type of buttons in the mouse. This event will be fired with
the help of keyboard.
Syntax:
-----------------
End sub
Left vb left 1
Right vb right 2
middle vb middle 4
B.Balaji (b.balag@gmail.com)
Page 50 of 62
Shift and ctrl and alt key vb shift and ctrl and alt mark 7
For every mouse drag drop and drag over events will be executed using x and y axis parameters, this
tells the event where the control to be moved or drag from the form.
Drag mode property this property enables whether the drag mode is automatic or manual. If
the value = 1, then the drag mode property is in automatic mode. If the
value = 0, it is in manual dragging mode.
Drag icon property it sets the mouse icon, to user defined icon, while you enable the drag
mode property.
Drag method it enables to execute the start and stop methods inside the drag mode
Property. If you enable drag mode property. If you enable drag mode
property to manual.
Drag drop property it is used to allow the controls to drop the source control.
Drag over property it is used to control the source, while passing other controls during drag
option.
B.Balaji (b.balag@gmail.com)
Page 51 of 62
Image1.Picture = LoadPicture
End Sub
Image1.Picture = LoadPicture
End Sub
Dialog box:
These are used to interact between the users and the common system usage dialog box are used to
interact between the users as a user friendly tool kid (vtk). Vb allows to create 3 difference type of
dialog box.
Every application can have only one common dialog box control, you can use different type of methods
to execute the common dialog box control.
Methods description
B.Balaji (b.balag@gmail.com)
Page 52 of 62
Show open() this method is used to open an existing file from the selected directory, inside
your application. It will use file name and file type property.
Show save() it is used to open a save dialog box inside you current directory of your
application. You can also use the file filter property to extend the save method.
Show print() this method is used to print the current opened file from the application.
Show font() it will open a font dialog box and you can select the font style or font file for a
select text is the application.
Show color() this method is used to set the color for the selected text inside the application.
This must be closed before or you need to response before, you can continue with the rest of your
application. A dialog box which opens when your child an application. You need to respond the
application either by using or by not saving or resuming the application by cancelling.
This type of dialog box are used to shift the focus from the dialog box without closing and move the
cursor to the current running application.
eg: adding 2 find and replace dialog box inside your application. It helps the user to switch owns the
focus b/w the dialog box and application.
These are used to a return a value from a function to the standard forms. This type of functions are
known as property functions or property procedures when you start up a applications in visual basic. By
default, every application will be started from either code module of a normal form or mdi form. If you
B.Balaji (b.balag@gmail.com)
Page 53 of 62
are not having a default start up object, you can able to manage with a do event function to load the
application. This function can be done inside sub-procedures code module window.
Sub main:
Sub main functions are used to create a separate starting page inside the application. To enable the sub-
main function to choose the project menu and then select the project properties and select the startup
object to sub-main function. This will open a separate code module window which are used to write a
procedures for enabling or disabling available forms inside the current applications.
Syntax:
Sub main()
Form objects
End sub
Eg:
Sub main()
Form splash.refresh
Form splash.show
Form1.show
End sub
Form splash used to check vb application with different type of form availability and it will sort out the
availability forms in current applications.
B.Balaji (b.balag@gmail.com)
Page 54 of 62
Unit-04
B.Balaji (b.balag@gmail.com)
Page 55 of 62
5) Using the folder collection, you can able to list out the sub folders and file collection.
6) Using file collection, you can execute the different type of methods for creating, deleting,
copying folders, sub-folders and files.
Copy file source des [overwrite] this method is used to copy file from source path to destination
path overwrite is used to explicit the file.
Copy folder source des [overwrite] it copies a folder or directories including sub –folders and files.
Create folder [folder name] it will create a new folder under the current driver with the
specific folder name.
Delete file [file specified] it will delete the file which has been specify under, file name.
Delete folder [folder specify] it will delete the folder, including sub-folder and files.
Move file source des [overwrite] it will move the specified file from the source path to
destination path.
Move folder source, des [overwrite] it moves the folder including subfolders and files.
Get base name it will return a string, that displays the name of a file or folder
Get file, [file specified] it will return a file object corresponding to the specified file
name.
File1.Path = Dir1.Path
End Sub
Dir1.Path = Drive1.Drive
End Sub
B.Balaji (b.balag@gmail.com)
Page 56 of 62
Image1.Stretch = True
End Sub
You can also use built in functions to find out the binary search.
For example, you can use a string compare functions, string length function, vbound and lboung
methods to find out the limits
Sorting:
Sorting a data is one of the most common jobs for a huge database, by using a sorting algorithms, you
can arrange the database orders and fetch the database values according to the users needs.
1) Ripple sort.
2) Insertion sort.
3) Bubble sort.
4) Shell sort.
You can able to ass extra sorting algorithms inside vb application. Unfortunately some of the sorting
methodologies cant be proceed and difficult to write inside vb application.
B.Balaji (b.balag@gmail.com)
Page 57 of 62
connecting with database. Each and every control has different type of property which is used to
interact with database server.
1) Connection objects.
2) Data providers.
Connection objects:
This is used to maintain a connection to a database table. Every connection object will create a
command object and record set objects using a single connection object you can able to connect
multiple access to multiple database servers mainly, connection object is used to selecting the values,
inserting the values, updating the values and deleting the values from the table.
It is a string data type containing the information which is used to connect the data source.
Providers:
It is used to close the current connection object from the database server.
Default database:
Open:
Close:
This is used to close the connection from the data provider. It also close all the transaction without
updating or saving the data tables.
Cancel method:
It is used to terminate the transaction without saving the values in data table.
B.Balaji (b.balag@gmail.com)
Page 58 of 62
Data providers:
Data providers are use to connect database server and vb application. For example data providers such
as, ms-access, oracle, sql server, etc.,
By default, vb as a database provider within the addins, named as visual data manager.
Types of databases:
Ms database programming has 3 different types of database object.
It is a standard control within the vb application x used to serve default database links. The default
database in dao object is ms jet database. Jet database uses link between the vb application and ms
access database.
1) Database engine:
It is used to set the database provider name to the vb application. You can find different type of
available database serves inside the system. For eg, if the system has database server, link access,
sql server, oracle etc.,.
2) Work space:
It is used to add or more database table from the database engine.
3) Record set:
It is used to set the result. Query from the data table.
4) This property is used to return the columns from the selected record set table.
B.Balaji (b.balag@gmail.com)
Page 59 of 62
Using rdo connection, you can link the database as a third party database to the vb application. Every vb
application can built rdo connection for client server application. Using ODBC active interface, you can
connect both local database Server X REMOTE DATABASE SERVERS.
Once you create a object in ODBC you can link the reference to rdo connection. The one main feature of
having a rdo object is you can create a database by defining the object of odbc interface.
Ado control:
Adodc is designed to create an connection to a database server form ms vb. This control is used to
create a dynamic connection to various database server using ole db provider. You can create a set of
record source and can create custom sqp statements to using the data control.
Properties in adodc:
1) Recordset:
It is used to set the database table from the ole db provider. It also used to move different type of
methods inside the adodc.
2) Fields:
It is an object reference, which used to select the columns from data table.
B.Balaji (b.balag@gmail.com)
Page 60 of 62
2) Update:
3) Delete:
4) Move first:
It is used to move the current record pointer to the first record into the recordset property.
5) Move last:
It is used to move the current record pointer to the last record into the recordset property
6) Move next:
It is used to move the current record pointer to the next record into the recordset property.
7) Move previous:
It is used to move the current record pointer to the presvious record into the recordset property.
B.Balaji (b.balag@gmail.com)
Page 61 of 62
Creating a table:
1) After creating the database, right click anywhere inside the windows of database. This will
display a table structure for creating the table.
2) Enter the name of the table in table name field you should not add duplicate names.
3) To add column or fields click on add field dialog box, it will open a dialog window for entering
new columns.
4) You can choose different types of data types for each and every columns. You can alos use size
of the data type, default value for data type and validation for the variables.
5) After creating the columns, press on the built the table, to create the table.
Data environment:
This designer is a tool in vb to create a database application more faster than, any other database
controls. The data environment designer will work with ado object model technology dao and rdo object
model are not supported in data environment designer. To ass a data environment designer choose on
the project properties. Add data environment in designer tab and apply in to the vb application.
To connect is database within data environment designer, you need to add the following commands.
Add connection:
It is used to add a connection object environment, which will be used to access a database server.
Add command:
It creates a new command object to the create environment which can use to execute an sql command.
Design:
It is used to access the sql query designer when you specify the sql statement data source for command
object.
View code:
Delete:
Refresh:
B.Balaji (b.balag@gmail.com)
Page 62 of 62
1) Reports header:
It is used to print only once within bigger font size of the report.
2) Page header:
It is used to print different type of titles of top of each page of the report.
3) Group header:
It is used to print different type of text for each and every command object in record set.
4) Detail:
It is used to print different type of each and every records retrieved from data type.
5) Group footer:
It is used to print at end of corresponding group header section.
6) Page footer:
It is used to print at the bottom of each page of reports.
7) Report footer:
B.Balaji (b.balag@gmail.com)