VB Lab Manual 2009-2010
Contents
1. Generate one example using Text,Label,Command Button
ontrols and also !rite appropriate e"ents #or t$at
2. Create an %ppliation &sing 'ption Button and C$e( Boxes
). Create an appliation &sing *i##erent Combo and List Box
ontrols
+. Generate one example using *ata Control and also !rite
appropriate e"ents #or t$at
,. Create a Calulator %ppliation
-. Create an appliation using *i##erent Grid Controls
.. Generate one example !it$out using *ata Control
/. Create an appliation using 0ori1antal and Vertial 2roll Bars
9. Create an appliation using Menus
[Link] an appliation &sing M*3 #orm !it$ Toolbar ontrol
11. Create an %ppliation &sing *irListbox, *ri"eListbox , 4ile
Listbox ontrols
[Link] an appliation &sing 5opup Menus
1).Create an appliation &sing 2$ape and Timer ontrols
5repared b6 7.V.2. 5a"an 8umar
1. Generate One Example using Text,Label,Command Button controls and also write
appropriate events for tat
!rivate "ub cmd#Exit#Clic$%&
'nload (e
End "ub
!rivate "ub cmd#O$#Clic$%&
(sgBox ) *eg.+O, ) - txt#*eg+[Link] - ) +ame, ) - #
txt#[Link] - ) .ddress, ) - txt#[Link] - #
) Branc, ) - txt#[Link]
End "ub
!rivate "ub Lbl#(essage#/blClic$%&
(sgBox %) tis is a label to sow te events and messages)&
End "ub
!rivate "ub txt#.ddress#Lost0ocus%&
Lbl#([Link] 1 )txt#.ddress#Lost0ocus event)
End "ub
!rivate "ub Txt#+ame#Cange%&
Lbl#([Link] 1 )+o. of letters in name ,) - Len%txt#[Link]&
End "ub
!rivate "ub txt#*eg+o#Got0ocus%&
Lbl#([Link] 1 )txt#*eg+o#Got0ocus event)
End "ub
2. Create .n .pplication 'sing Option Button and Cec$ Boxes
!rivate "ub Cmd#Calculate#Clic$%&
3f txt#[Link] 1 )) Ten
(sgBox %)Enter Basic )&
Exit "ub
End 3f
3f txt#/[Link] 1 )) Ten
(sgBox %)Enter /eductions)&
Exit "ub
End 3f
txt#/..Text 1 4al%txt#[Link]& 5 16
txt#T..Text 1 4al%txt#[Link]& 5 17
txt#8*..Text 1 4al%txt#[Link]& 5 26
txt#Gross![Link] 1 4al%txt#[Link]& : #
4al%txt#/..Text& : 4al%txt#8*..Text& : 4al%txt#T..Text&
txt#+et![Link] 1 4al%txt#Gross!a9& ; 4al%txt#/eductions&
End "ub
!rivate "ub cmd#Exit#Clic$%&
'nload (e
End "ub
!rivate "ub Cmd#+ew*ecord#Clic$%&
txt#Emp+[Link] 1 ))
txt#[Link] 1 ))
txt#[Link] 1 ))
txt#/..Text 1 ))
txt#8*..Text 1 ))
txt#T..Text 1 ))
txt#Gross![Link] 1 ))
txt#/[Link] 1 ))
txt#+et![Link] 1 ))
End "ub
!rivate "ub 0orm#Load%&
(e.<indow"tate 1 2
End "ub
= Create an application 'sing /ifferent Combo and List Box controls
.
>. Generate one example using /ata Control and also write appropriate events for tat
7. Create a Calculator application
/im ? .s /ouble
/im @ .s /ouble
/im A .s /ouble
/im op .s 3nteger
/im f .s 3nteger
!rivate "ub Command#Clic$%3ndex .s 3nteger&
? 1 %? B 16& : 3ndex
[Link] 1 ?
End "ub
!rivate "ub Command1#Clic$%3ndex .s 3nteger&
@ 1 ?
? 1 6
op 1 3ndex
3f %op 1 7& Ten
f 1 @ 5 16
A 1 f
[Link] 1 A
? 1 A
End 3f
End "ub
!rivate "ub Command2#Clic$%&
"elect Case op
Case 6, A 1 @ : ?
Case 1, A 1 @ ; ?
Case 2, A 1 @ B ?
Case =, A 1 @ 5 ?
Case >, A 1 9(odx
Case 7, f 1 @ 5 16
A 1 f
End "elect
[Link] 1 A
? 1 A
op 1 6
End "ub
!rivate "ub Command=#Clic$%&
? 1 6
@ 1 6
A 1 6
f 1 6
op 1 6
[Link] 1 A
End "ub
!rivate "ub 0orm#Load%&
? 1 6
@ 1 6
A 1 6
op 1 111
f 1 6
[Link] 1 ))
End "ub
C. Create an application using /ifferent Grid Controls
D. Generate one example witout using /ata Control
/im db .s /atabase
/im rs .s *ecordset
/im rs1 .s *ecordset
/im sEl .s "tring
!rivate "ub Cmd#/elete#Clic$%&
"et rs1 1 [Link]*ecordset%)select count%B& from student1 were rollno1) - #
4al%Txt#*Oll+[Link]&&
3f Txt#*Oll+[Link] 1 )) Ten
(sgBox )enter a valid roll number)
Exit "ub
End 3f
3f rs1%6& 1 6 Ten
(sgBox %)tere are no records wit tis roll number)&
Exit "ub
End 3f
[Link] %)delete from student1 were rollno1) - #
4al%Txt#*Oll+[Link]&&
(sgBox %)record deleted)&
End "ub
!rivate "ub Cmd#Edit#Clic$%&
Clear#Controls
Cmd#[Link] 1 0alse
End "ub
!rivate "ub cmd#Exit#Clic$%&
'nload (e
End "ub
!rivate "ub Cmd#"ave#Clic$%&
3f Cmd#[Link] 1 0alse Ten
sEl 1 ) insert into student1 values%) - #
C3nt%Txt#*Oll+[Link]& - ),F) - #
Txt#+[Link] - )F,F) - #
Txt#.[Link] - )F,) - #
C/bl%Txt#(obile+[Link]& - )&)
(sgBox sEl
[Link] %sEl&
(sgBox %)record inserted)&
Cmd#[Link] 1 True
End 3f
3f Cmd#[Link] 1 0alse Ten
sEl 1 )update student1 set name1F) - Txt#+[Link] - ) F,address1F) - #
Txt#.[Link] - )F,mobilenumber1) - #
C/bl%Txt#(obile+[Link]& - ) were %*oll+O1 ) - #
C3nt%Txt#*Oll+[Link]& - )&)
(sgBox sEl
[Link] %sEl&
(sgBox %)record updated)&
Cmd#[Link] 1 True
End 3f
End "ub
!rivate "ub 0orm#Load%&
"et db 1 Open/atabase%)/,GpavanG4bLab(anualG![Link]), True&
"et rs 1 [Link]*ecordset%)student1), dbOpen/9naset&
rs.(ove0irst
F"ow#/ata
End "ub
!rivate "ub Cmd#0irst#Clic$%&
rs.(ove0irst
"ow#/ata
End "ub
!rivate "ub Cmd#Last#Clic$%&
rs.(oveLast
"ow#/ata
End "ub
!rivate "ub Cmd#+ext#Clic$%&
rs.(ove+ext
"ow#/ata
End "ub
!rivate "ub Cmd#!revious#Clic$%&
rs.(ove!revious
"ow#/ata
End "ub
!rivate "ub Cmd#3nsert#Clic$%&
Clear#Controls
Cmd#[Link] 1 0alse
Txt#*Oll+o."et0ocus
End "ub
!rivate "ub "ow#/ata%&
3f rs.EO0 Ten
rs.(oveLast
End 3f
3f rs.BO0 Ten
rs.(ove0irst
End 3f
Txt#*Oll+[Link] 1 rs%6&
Txt#+[Link] 1 rs%1&
Txt#.[Link] 1 rs%2&
Txt#(obile+[Link] 1 rs%=&
End "ub
!rivate "ub Clear#Controls%&
Txt#*Oll+[Link] 1 ))
Txt#+[Link] 1 ))
Txt#.[Link] 1 ))
Txt#(obile+[Link] 1 ))
End "ub
H. Create an application using 8oriAantal and 4ertical "croll Bars
/im obI .s ObIect
!rivate "ub c$#Bold#Clic$%&
3f c$#Bold.4alue 1 1 Ten
[Link] 1 True
Else
[Link] 1 0alse
End 3f
End "ub
!rivate "ub c$#3talic#Clic$%&
3f c$#3talic.4alue 1 1 Ten
obI.3talic 1 True
Else
obI.3talic 1 0alse
End 3f
End "ub
!rivate "ub c$#"tri$e#Clic$%&
3f c$#"tri$e.4alue 1 1 Ten
obI."tri$etroug 1 True
Else
obI."tri$etroug 1 0alse
End 3f
End "ub
!rivate "ub c$#'nderline#Clic$%&
3f c$#'nderline.4alue 1 1 Ten
obI.'nderline 1 True
Else
obI.'nderline 1 0alse
End 3f
End "ub
!rivate "ub 0orm#Load%&
"et obI 1 Txt#"ample.0ont
End "ub
!rivate "ub 8"*#*ed#Cange%&
Txt#"[Link]$Color 1 *GB%4al%8"*#*ed&, 4al%8"*#Green&, 4al%8"*#Blue&&
End "ub
!rivate "ub 8"*#Green#Cange%&
Txt#"[Link]$Color 1 *GB%4al%8"*#*ed&, 4al%8"*#Green&, 4al%8"*#Blue&&
End "ub
!rivate "ub 8"*#Blue#Cange%&
Txt#"[Link]$Color 1 *GB%4al%8"*#*ed&, 4al%8"*#Green&, 4al%8"*#Blue&&
End "ub
!rivate "ub 4"*#*ed#Cange%&
Txt#"[Link]$Color 1 *GB%4al%4"*#*ed&, 4al%4"*#Green&, 4al%4"*#Blue&&
End "ub
!rivate "ub 4"*#Green#Cange%&
Txt#"[Link]$Color 1 *GB%4al%4"*#*ed&, 4al%4"*#Green&, 4al%4"*#Blue&&
End "ub
!rivate "ub 4"*#Blue#Cange%&
Txt#"[Link]$Color 1 *GB%4al%4"*#*ed&, 4al%4"*#Green&, 4al%4"*#Blue&&
End "ub
J. Create an application using (enus
Option Explicit
/im db .s /atabase
/im rs .s *ecordset
/im rs1 .s *ecordset
/im sEl .s "tring
/im insert#flag .s Boolean
/im update#flag .s Boolean
!rivate "ub 0orm#Load%&
"et db 1 Open/atabase%)/,GpavanG4bLab(anualG![Link]), True&
"et rs 1 [Link]*ecordset%)student1), dbOpen/9naset&
rs.(ove0irst
F"ow#/ata
End "ub
!rivate "ub insert#Clic$%3ndex .s 3nteger&
Clear#Controls
insert#flag 1 True
Txt#rollno."et0ocus
End "ub
!rivate "ub delete#Clic$%3ndex .s 3nteger&
"et rs1 1 [Link]*ecordset%)select count%B& from student1 were rollno1) - #
4al%Txt#[Link]&&
3f Txt#[Link] 1 )) Ten
(sgBox )enter a valid roll number)
Exit "ub
End 3f
3f rs1%6& 1 6 Ten
(sgBox %)tere are no records wit tis roll number)&
Exit "ub
End 3f
[Link] %)delete from student1 were rollno1) - #
4al%Txt#[Link]&&
(sgBox %)record deleted)&
End "ub
!rivate "ub update#Clic$%3ndex .s 3nteger&
Clear#Controls
update#flag 1 True
End "ub
!rivate "ub mnu#save#Clic$%&
3f insert#flag 1 True Ten
sEl 1 ) insert into student1 values%) - #
C3nt%Txt#[Link]& - ),F) - #
txt#[Link] - )F,F) - #
txt#[Link] - )F,) - #
C/bl%txt#[Link]& - )&)
(sgBox sEl
[Link] %sEl&
(sgBox %)record inserted)&
insert#flag 1 0alse
End 3f
3f update#flag 1 True Ten
sEl 1 )update student1 set name1F) - txt#[Link] - ) F,address1F) - #
txt#[Link] - )F,mobilenumber1) - #
C/bl%txt#[Link]& - ) were %*oll+O1 ) - #
C3nt%Txt#[Link]& - )&)
(sgBox sEl
[Link] %sEl&
(sgBox %)record updated)&
update#flag 1 0alse
End 3f
End "ub
!rivate "ub first#Clic$%3ndex .s 3nteger&
rs.(ove0irst
"ow#/ata
End "ub
!rivate "ub last#Clic$%3ndex .s 3nteger&
rs.(oveLast
"ow#/ata
End "ub
!rivate "ub next#Clic$%3ndex .s 3nteger&
rs.(ove+ext
"ow#/ata
End "ub
!rivate "ub previous#Clic$%3ndex .s 3nteger&
rs.(ove!revious
"ow#/ata
End "ub
!rivate "ub end#Clic$%&
'nload (e
End "ub
!rivate "ub "ow#/ata%&
3f rs.EO0 Ten
rs.(oveLast
End 3f
3f rs.BO0 Ten
rs.(ove0irst
End 3f
Txt#[Link] 1 rs%6&
txt#[Link] 1 rs%1&
txt#[Link] 1 rs%2&
txt#[Link] 1 rs%=&
End "ub
!rivate "ub Clear#Controls%&
Txt#[Link] 1 ))
txt#[Link] 1 ))
txt#[Link] 1 ))
txt#[Link] 1 ))
End "ub
16. Create an application 'sing (/3 form wit Toolbar control
!rivate "ub Toolbar1#ButtonClic$%B94al Button .s ("[Link]&
"elect Case Button.Ke9
Case )!rogram1)
Load frm#!rg1
frm#!rg1."ow
frm#!rg1."et0ocus
Case )!rogram2)
Load frm#!rg2
frm#!rg2."ow
frm#!rg2."et0ocus
Case )Combo)
Load frm#!rg=
frm#!rg=."ow
frm#!rg=."et0ocus
Case )Grid)
Load frm#!rgC
frm#!rgC."ow
frm#!rgC."et0ocus
Case )8oriAantal)
Ffrm#(/30orm..rrange %vbfile8oriAantal&
frm#(/30orm..rrange %1&
Case )4ertical)
Ffrm#(/30orm..rrange %vbfilevertical&
frm#(/30orm..rrange %2&
Case )Cascade)
Ffrm#(/30orm..rrange %vbfilecascade&
frm#(/30orm..rrange %6&
End "elect
End "ub
11. Create .n .pplication 'sing /irListbox, /riveListbox , 0ile Listbox controls
!rivate "ub /ir1#Cange%&
0ile1.!at 1 /ir1.!at
End "ub
!rivate "ub /rive1#Cange%&
/ir1.!at 1 /rive1./rive
End "ub
!rivate "ub cmd#[Link]/rives#Clic$%&
F "can te contents of te /riveListBox control
[Link]
List1..dd3tem )L3"T O0 /*34E")
0or i 1 6 To /[Link] ; 1
List1..dd3tem /[Link]%i&
+ext
End "ub
!rivate "ub cmd#List.ll0iles#Clic$%&
F "can te contents of te 0ileListBox control
[Link]
List1..dd3tem )L3"T O0 03LE")
0or i 1 6 To [Link] ; 1
List1..dd3tem [Link]%i&
+ext
End "ub
!rivate "ub cmd#[Link]"ub0olders#Clic$%&
F "can te contents of te /irListBox control
[Link]
List1..dd3tem )L3"T O0 "'B0OL/E*")
0or i 1 6 To /[Link] ; 1
List1..dd3tem /[Link]%i&
+ext
End "ub
!rivate "ub cmd#[Link]!arent0olders#Clic$%&
[Link]
List1..dd3tem )L3"T O0 !.*E+T 0OL/E*")
p/ept 1 ;1
<ile /[Link]%p/ept& LM ))
List1..dd3tem /[Link]%p/ept&
p/ept 1 p/ept ; 1
<end
List1..dd3tem )Te current folder is nested ) - #
;p/ept : 1 - ) folders deep)
End "ub
12. Create an application 'sing !opup (enus
!rivate "ub mnu#frm#!rogram1#Clic$%&
(sgBox )mnu#frm#!rg1)
Load frm#!rg1
frm#!rg1."ow
End "ub
!rivate "ub mnu#frm#!rogram2#Clic$%&
(sgBox )mnu#frm#prg2)
Load frm#!rg2
frm#!rg2."ow
End "ub
!rivate "ub mnu#ComboandList#Clic$%&
(sgBox )mnu#ComboandList)
Load frm#!rg=
frm#!rg=."ow
End "ub
!rivate "ub mnu#GridControls#Clic$%&
(sgBox )mnu#frm#GridControls)
Load frm#!rgC
frm#!rgC."ow
End "ub
1=. Create an application 'sing "ape and Timer controls
!rivate "ub Timer1#Timer%&
"ape1.(ove "[Link] : "cale<idt B %*nd ; 6.7& 5 76, "[Link] : "cale8eigt
B %*nd ; 6.7& 5 76
"ape2.(ove "[Link] : "cale<idt B %*nd ; 6.7& 5 76, "[Link] : "cale8eigt
B %*nd ; 6.7& 5 76
"ape=.(ove "ape=.Left : "cale<idt B %*nd ; 6.7& 5 76, "ape=.Top : "cale8eigt
B %*nd ; 6.7& 5 76
"ape>.(ove "ape>.Left : "cale<idt B %*nd ; 6.7& 5 76, "ape>.Top : "cale8eigt
B %*nd ; 6.7& 5 76
End "ub