0% found this document useful (0 votes)
343 views93 pages

Visual Basic Pratice Question and Answer

This document describes a Visual Basic program that counts the different characters in an input string. It includes an interface with labels and text boxes. The coding counts vowels, consonants, digits, and special characters by iterating through the string and checking the character type. It will display the totals for each type of character. The program allows the user to enter a string and click a button to count and display the results.

Uploaded by

Nitesh Bhura
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
343 views93 pages

Visual Basic Pratice Question and Answer

This document describes a Visual Basic program that counts the different characters in an input string. It includes an interface with labels and text boxes. The coding counts vowels, consonants, digits, and special characters by iterating through the string and checking the character type. It will display the totals for each type of character. The program allows the user to enter a string and click a button to count and display the results.

Uploaded by

Nitesh Bhura
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 93

1

VB PRACTICAL

Q1. WAP TO PERFORM ARITHMETIC OPERATION USING COMMAND


BUTTONS
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: I
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/Arthmatic
Date
: 13/09/2011
Solution:
Step1 :User Interface & Properties of the Controls -

SN
o

Name of the
controls

Form1

Label1

Label 2

Label 3

Property

Value

Name

arthmaticform
Arithmetic
Operations

Caption
windowStat
e
Name
Caption
Name
Caption
Name
Caption

2-maximized
Label1
Enter First Number
Label2
enter second
number
Label3
Result

VB PRACTICAL

Label 4

Text 1

Text 2

Frame

Command 1

10

Command 2

11

command 3

12

command 4

13

command 5

STEP 2 :-

CODING

Name
Caption
Name
Text
Name
Text
Name
Caption
Name
Caption
Name
Caption
Name
caption
Name
caption
Name
caption

Label4
Blank
Text1
Blank
Text2
Blank
Frame1
Blank
Command1
&Add
Command2
Subtract
Command3
multiply
Command4
divide
Command5
exit

private sub command1_click(index as integer)


a = val(text1.text)
Entering numbers
b = val(text2.text)
select case command1(index).caption
case "&add"
label3.caption = a + b
Adding numbers
case "subtract"
label3.caption = a b
Subtracting numbers
case "multiply"
label3.caption = a * b
multiplying numbers
case "divide"
label3.caption = a / b
division numbers
case "exit"
end
end select
end sub

STEP 3 :- OUTPUT :
ADDITION :
SUBTRACTION:

MULTIPLICATION
DIVISION

VB PRACTICAL

VB PRACTICAL

Q2. WAP TO TAKE INPUT OF PRINCIPAL, RATE, & TIME AND


CALCULATE SIMPLE INTEREST & COMPOUND INTEREST.
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: I
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/simpleinterest
Date
: 13/09/2011
Solution:
Step1 :User Interface & Properties of the Controls -

Sn
o.

Name of the
controls

Form

Label 1

Label 2

Label 3

Property

Value

Name

Form1

Caption

Wap to
calculate
simple
interest and
compound
interest

Window state

2-maximized

Name

Label1
Enter
principal
Label2
Enter rate
Label3

Caption
Name
Caption
Name

VB PRACTICAL

Caption
Name
Caption
Name
Text
Name
Text
Name
Text
Name

Label 4

Text 1

Text 2

Text 3

Command 1

10

Command 2

11

Command 3

Caption
Name

STEP 2 :-

CODING

Caption
Name
Caption

Enter time
Label4
Blank
Text1
Blank
Text2
Blank
Text3
Blank
Command1
Simple
interest
Command2
Compound
interest
Command3
Exit

general declaration
Dim p, q, r, SI, x, CI As Integer
Private Sub Command1_Click()
p = Val(Text1.Text)
q = Val(Text2.Text)
r = Val(Text3.Text)
SI = (p * q * r) / 100
'calculating simple interest
Label4.Caption = SI
End Sub
Private Sub Command2_Click()
p = Val(Text1.Text)
q = Val(Text2.Text)
r = Val(Text3.Text)
CI = (p * (1 + q / 100) ^ r) - p
Label4.Caption = CI
'calculating compound interest
End Sub
Private Sub Command3_Click()
End
End Sub

VB PRACTICAL

STEP 3 :-

OUTPUT

SIMPLE INTEREST
COMPOUND INTEREST

VB PRACTICAL

Q3. WAP TO TAKE INPUT OF X AND PRINT TABLE


FOLLOWING FORMAT
X*1=X
X*2=2X
X*10=10*X
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: I
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/multiplication
Date
: 13/09/2011
Solution:
Step1 :User Interface & Properties of the Controls -

OF X IN THE

VB PRACTICAL

Sn
o.

Name of the
controls

Form

Label 1

Text 1

Command 1

Command 2

Property

Value

Name

Form1

Caption

Form1

Window state

2-maximized

Name

Label1
Enter value
for x
Text1
Blank
Command1

Caption
Name
Text
Name
Caption
Name
Caption

Multiplication
Table
Command2
Exit

STEP 2 :CODING :
Private Sub Command1_Click()
Dim x, s As Integer
x = Val(Text1.Text)
'general declaration
For y = 1 To 10
'for loop begin
z = x * y
Print x; "*"; y; "="; z
Next
'for loop ends
End Sub
Private Sub Command2_Click()
End
End Sub
STEP

3:-

OUTPUT

VB PRACTICAL

Q4. Design an interface, which will appear like markshet .it will
take input of marks in five subjects and calculate total marks
and percentage then provide grade according to following
criteria
If %
then grade
>=90
a+
>=75 & <90
a
>=60 & <75
b
>=45 & <60
c
Otherwise
f
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: I
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/marksheet
Date
: 13/09/2011
solution:Step1:-User Interface & Properties of the Controls-

VB PRACTICAL

10
FORM1
FORM 2:-

Sn
o.

Name of
the
Controls

Form 1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

Label
Label
Label
Label
Label
Label
Label
Label
Label
Label
Label
Label
Label
Label
Label
Label
Label
Label
Label
Label
Label
Label

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

Property

Value

Window state

2-maximized

Name
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption

Form1
Form1
Name of the university
Enter name
Enter rollno
Enter class
Subject name
Max marks
Min marks
Marks obtd.
Pc soft
100
40
Visual basic
100
40
C language
100
40
Maths
100
40
It
100

11

24
25
26
27
28
29
30
31
32
33
34
35

Label 23
Text 1
Text 2
Text 3
Text 4
Text 5
Text 6
Text 7
Text 8
Text 9
Command 1
Command 2

36

Form 1

37
38
39
40
41
42
43
44

Label 1
Label 2
Label 3
Label 4
Label 5
Label 6
Label 7
Label 8
STEP 2 : CODING

VB PRACTICAL
Caption
Text
Text
Text
Text
Text
Text
Text
Text
Text
Caption
Caption
WindowState
Name
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
:

40
Blank
Blank
Blank
Blank
Blank
Blank
Blank
Blank
Blank
>>output
Get result
2-maximized
Form2
Form2
Enter rollno.
Enter pecentage
Enter div
Enter total
Blank
Blank
Blank
Blank

Dim div As String


Dim rno, m1, m2, m3, m4, m5, total, per As Integer
Private Sub Command1_Click()
Form2.Show
Form2.Label5.Caption= rno
Form2.Label6.Caption= per
Form2.Label7.Caption= div
Form2.Label8.Caption= total
End Sub
Private Sub Command2_Click()
rno = Val(Text3.Text)
m1 = Val(Text4.Text)
m2 = Val(Text5.Text)
m3 = Val(Text6.Text)
m4 = Val(Text7.Text)
m5 = Val(Text8.Text)
total = m1 + m2 + m3 + m4 + m5
per = total / 5
If per >= 90 Then
div = "A+"

VB PRACTICAL

12

Else
If per >= 75 Then
div = "A"
Else
If per >= 60 Then
div = "B"
Else
If per >= 45 Then
div = "C"
Else
div = "Fail"
End If
End If
End If
End If
End Sub

STEP

3:-

OUTPUT

13

Q5.WAP

VB PRACTICAL

TO CREATE A SIMPLE CALCULATOR(USING CONTROL ARRAY).

Author name : Surabhi Roy


Class
: BCA I
Unit No.
: I
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/calculator
Date
: 16/09/2011
Solution:Step1:-User Interface & Properties of the Controls-

VB PRACTICAL

14

Sn
o.

Name of
the
Controls

Form 1

2
3

Text1
Frame 1

Command 1

Command 2

Command 3

Command 4

Command 5

Property

Value

Window state
Fon
t
Fon
t
styl
Font
e
Fon
t
siz
e
Caption
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name

2-maximized
Times New
Roman
Bold italic

14
Blank
Blank
Command
1
Command
2
Command
3
Command
4
Command

1
1
1
1
1

VB PRACTICAL

15

10

Command 6

11

Command 7

12

Command 8

13

Command 9

14

Command
10

15

Command
11

16

17

Command
13

18

Command
14

19

20

21
STEP 2 :

Command
12

CODING

Command
15
Command
16
Command
17

Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption

5
Command
6
Command
7
Command
8
Command
9

1
1
1
1

Name

Command 1

Caption

Name

Command 2

Caption

Name

Command 2

Caption

Name

Command 2

Caption

Name

Command 2

Caption

Name

Command 3

Caption

Name

Command 5

Caption

Name

Command

Caption

Clear

general declaration
Dim oldval, newval As Integer
Dim opt As String
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text + Command1(Index).Caption
End Sub
Private Sub Command2_Click(Index As Integer)

16

VB PRACTICAL

oldval = Val(Text1.Text)
opt = Command2(Index).Caption
Text1.Text = ""
End Sub
Private Sub Command3_Click()
newval = Val(Text1.Text)
Select Case opt
Case "+"
Text1.Text = (oldval + newval)
Case "-"
Text1.Text = (oldval - newval)
Case "x"
Text1.Text = (oldval * newval)
Case "/"
Text1.Text = (oldval / newval)
End Select
End Sub
Private Sub Command5_Click()
newval = Val(Text1.Text)
Text1.Text = (oldval * newval) / 100
End Sub
Private Sub Command6_Click()
Text1.Text = ""
oldval = 0
newval = 0
End Sub
STEP

3:-OUTPUT :

17

VB PRACTICAL

Q6.WAP TO CHECK WHETHER AN ENTERED NO. IS PRIME OR NOT.

Author name : Surabhi Roy


Class
: BCA I
Unit No.
: I
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/prime
Date
: 16/09/2011
solution:Step1:-User Interface & Properties of the Controls-

SN
o.

Name of the
Control

1.

Form

2.

Label

3.

Text box

4.

Label

5.

Command
button

Property

Value

Name
Caption
WindowStat
e
Name
Caption
Name
Caption
Name
Caption
Name

Form1
PRIME NUMBER

Caption

2-Maximized
Label1
Enter number.
Text1
blank
Label2
Blank
Command1
Check whether
prime or not

18

STEP

2:

VB PRACTICAL

CODING:

Private Sub Command1_Click()


a = 0
n = Val(Text1.Text)
For i = 1 To n Step 1
If n Mod i = 0 Then
a = a + 1
End If
Next
If a = 2 Then
Label2.Caption = "prime number"
Else
Label2.Caption = "not prime number"
End If
End Sub
STEP

3:OUTPUT:

VB PRACTICAL

19

Q7.

WAP WHICH WILL COUNT ALL VOWELS , CONSONANTS


CHARACTERS AND BLANK SPACES IN A SENTENCES.

DIGITS,SPECIAL

Author name : Surabhi Roy


Class
: BCA I
Unit No.
: I
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/characters
Date
: 21/09/2011
solution:
step 1: user interface & properties of controls :

Sno.

Name of the
Controls

Property
Window state
Name

Caption
1

Form 1
Font
Font

Label 1

Text 1

Font
style
Font
size

Name
Caption
Name

Value
2maximized
Frm_charact
ers
WAP to
create a
program
which will
count the
characters
Times New
Roman
Bold italic
14
Label1
Enter string
Label2

VB PRACTICAL

20

Caption
Name
4

Command 1

Caption

Blank
Label3
Count
characters

2:CODING :

STEP

Dim nm As String general declaration


Private Sub cmdCount_Click()
nm = Trim(txt1.Text)
For i = 1 To Len(nm)
ch = Mid$(nm, i, 1)
ch = UCase(ch)
Select Case ch
Case "A", "E", "I", "O", "U"
vowel = vowel + 1
Case "B" To "Z"
cons = cons + 1
Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"
num = num + 1
Case "@", "!", ",", "$", "?"
special = special + 1
Case " "
bl = bl + 1
End Select
Next
Print
Print
Print
Print
Print
End Sub

"No of Vowels =" & vowel


"No of Consonants =" & cons
"No of Digits=" & num
"No of special Characters =" & special
"blanks="; bl

VB PRACTICAL

21

STEP

3:-

OUTPUT

VB PRACTICAL

22

Q8. WAP TO ILLUSTRATE ALL FUNCTIONALITIES OF LISTBOX AND


COMBOBOX
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: I
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/listbox
Date
: 21/09/2011
solution:STEP 1:USING INTERFACE AND PROPERTIES OF CONTROLS

Sno.
1

Name of the
Controls
Form 1

Property

Value

WindowState

2-maximized

Name

Frm_charact
ers
Wap to
create a
program
which will
count the
characters
Arial
Bold italic

Caption

Font

List 1

Font
Font
style
Font
size
Caption

14
Blank

VB PRACTICAL

23

3
4
5
6
7
8
9
STEP

Combo1
Frame 1
Command
Command
Command
Command
Command
2: CODING :

1
2
3
4
5

Caption
Caption
Caption
Caption
Caption
Caption
Caption

Blank
Blank
Add
Add all
Move
Remove
Clear

Private Sub Command1_Click()


Combo1.AddItem List1.Text
End Sub
Private Sub Command2_Click()
List1.RemoveItem List1.ListIndex
End Sub
Private Sub Command3_Click()
For i = 0 To List1.ListCount - 1
Combo1.AddItem List1.List(i)
Next
End Sub
Private Sub Command5_Click()
Combo1.AddItem List1.Text
List1.RemoveItem List1.ListIndex
End Sub
Private Sub Command7_Click()
Combo1.Clear
End Sub
Private Sub Form_Load()
List1.AddItem "BCA-I"
List1.AddItem "BCA-II"
List1.AddItem "BCA-III"
List1.AddItem "PGDCA-I"
List1.AddItem "PGDCA-II"
List1.AddItem "BBA-I"
List1.AddItem "BBA-II"
List1.AddItem "BBA-III"
End Sub
STEP 3:OUTPUT:

24

VB PRACTICAL

Q9. WAP USING CHECK BOXES FOR FOLLOWING FONT EFFECTS.


BOLD
ITALIC
UNDERLINE
INCREASE FONT SIZE
DECREASE FONT SIZE
FONT COLOR
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: I
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/listbox
Date
: 23/09/2011
SOLUTIONS:STEP 1:- USING INTERFACE AND PROPERTIES OF CONTROLS

Sno Name of the


.
control
1.
Form

Property

Value

Name

Fontfrm1

25

VB PRACTICAL
Caption

2.

Label 1

3.
4.

Label 2
Text box

5.

Label

6.

Label

7.

Label

8.

Label

9.

List box

10.

Check box

11.

Check box

12.

Check box

13.

Combo box

14

Option button

15.

Option button

16.

Option button

17.

Option button

18.

Option button

19.

Option button

STEP

Window state
Name
Caption
Name
Name
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Name
Caption
Name
Caption
Name
Caption
Name
Text
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption

2:-CODING

Private Sub Check1_Click()


If Check1.Value = 1 Then
Label2.FontBold = True
Else
Label2.FontBold = False
End If

Fontcheckboxes
2-maximized
Label1
Enter text
Label2
Text1
Label3
Font
Label4
Style
Label5
Size
Label6
Color
List1
Check1
Bold
Check2
Italic
Check3
Underlined
Combo1
Combo1
Option1
Black
Option2
Blue
Option3
Red
Option4
Green
Option5
Yellow
Option6
White

26

VB PRACTICAL

End Sub
Private Sub Check2_Click()
If Check2.Value = 1 Then
Label2.FontItalic = True
Else
Label2.FontItalic = False
End If
End Sub
Private Sub Check3_Click()
If Check3.Value = 1 Then
Label2.FontUnderline = True
Else
Label2.FontUnderline = False
End If
End Sub
Private Sub Combo1_Click()
Label2.FontSize = Combo1.Text
End Sub
Private Sub Form_Load()
For i = 1 To Screen.FontCount
List1.AddItem Screen.Fonts(i)
Next i
For i = 10 To 100 Step 2
Combo1.AddItem i
Next i
End Sub
Private Sub List1_Click()
Label2.Font = List1.Text
End Sub
Private Sub Option1_Click()
If Option1.Value = True Then
Label2.ForeColor = vbRed
End If
End Sub
Private Sub Option2_Click()
If Option2.Value = True Then
Label2.ForeColor = vbBlue
End If
End Sub
Private Sub Option3_Click()
If Option3.Value = True Then
Label2.ForeColor = vbGreen
End If
End Sub
Private Sub Option4_Click()
If Option4.Value = True Then

27

VB PRACTICAL

Label2.ForeColor = vbYellow
End If
End Sub
Private Sub Option5_Click()
If Option5.Value = True Then
Label2.ForeColor = vbBlack
End If
End Sub
Private Sub Text1_Change()
Label2.Caption = Text1.Text
End Sub

STEP 3: OUTPUT :

28

VB PRACTICAL

Q10. WAP FOR TEMPERATURE CONVERSION USING OPTION BUTTON.


Author name : Surabhi Roy
Class
: BCA I
Unit No.
: I
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/ltemperature
Date
: 23/09/2011
SOLUTIONS:
STEP 1: USING INTERFACE AND PROPERTIES OF CONTROLS

STEP

2:CODING :

Dim c
Dim f
f =
Sn
o.
1.

Name of the
control
Form1

2.
3.
4.

Text box
Text box
Option button

5.

Option button

Property
Name
Caption

WindowStat
e
Name
Name
Name
Caption
Name
Caption

Private Sub Option1_Click()


As Double
As Double
Val(Text2.Text)
If
Value
(Option1.Value
= True) Then
Form1
c = 5 * (f Wap for
32) / 9
End If
temperature
Text1.Text = c
conversion
End Sub
using option
Private Sub
button
Option2_Click()
2-maximized
Dim c As Double
Dim f As Double
Text1
c =
Val(Text1.Text)
Text2
Option1
Centigrade
Option2
Fahrenheit

29

VB PRACTICAL

If (Option2.Value = True) Then


f = (9 * c / 5) + 32
End If
Text2.Text = f
End Sub
STEP 3:- OUTPUT

VB PRACTICAL

30

Q11.WAP TO LAUNCH A ROCKET USING PICTURE BOX AND TIMER


CONTROL.
Author name
Class
Unit No.
System No.
Path
Date

: Surabhi Roy
: BCA I
: III
: lab2,system11
: D:/Surabhi Vb Program/rocket
: 23/09/2011

SOLUTIONS:STEP 1:- USING INTERFACE AND PROPERTIES OF

Sn
o.
1.

2.

Name of the
Control
Form

Timer control

Commandbutto
n
STEP 2:CODING :

Property

Value

Name
Caption

Form1
Wap to launch a
rocket using
picture box and
timer control
2-Maximized

WindowStat
e
Name
Interval
Name
Caption

Dim x As Integer
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub

Timer1
10
Command1
Launch

CONTROLS

31

VB PRACTICAL

Private Sub Form_Load()


x = Image1.Top
End Sub
Private Sub Timer1_Timer()
Image1.Top = Image1.Top - 10
End Sub
STEP 3:OUTPUT:

32

VB PRACTICAL

Q12. WAP TO CHANGE BACKCOLOR OF ANY CONTROL (LABEL, TEXT)


USING SCROLL BOX
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: II
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/scroll
Date
: 26/11/2011
SOLUTIONS:STEP 1:-USING INTERFACE AND PROPERTIES OF

Sno
.

Name of the
control

1.

Form

2.

Label

3.

Text box

4.

Label

Property

Value

Name
Caption

Window stat
Name
Caption
Name

Form1
Wap to change
backcolor of any
control using
scroll bar
2-maximized
Label1
Blank
Text1

Caption
Name
Caption

Blank
Label2
blank

CONTROLS

33

VB PRACTICAL

STEP 2:CODING
Private Sub VScroll1_Change()
Label1.BackColor = RGB(VScroll1.Value, VScroll2.Value,
VScroll3.Value)
End Sub
Private Sub VScroll2_Change()
Text1.BackColor = RGB(VScroll1.Value, VScroll2.Value,
VScroll3.Value)
End Sub
Private Sub VScroll3_Change()
Label2.BackColor = RGB(VScroll1.Value, VScroll2.Value,
VScroll3.Value)
End Sub
STEP 3:- OUTPUT :

34

VB PRACTICAL

Q13. WAP TO SEARCH AN ELEMENT FOR A ONE DIMENSIONAL STATIC


ARRAY.
Author name
Class
Unit No.
System No.
Path
Date
SOLUTIONS:STEP 1:- USING

Sn
o.
1

Name of
the
Controls
Form 1

: Surabhi Roy
: BCA I
: II
: lab2,system11
: D:/Surabhi Vb Program/binary
: 26/11/2011
INTERFACE AND PROPERTIES OF

Property

Value

Window state
Caption

2maximized
Form1

Name

Form1

Font

Command

Font

Font
style
Font size
Caption

Arial
Regular
12
Binary
search

CONTROLS

35

VB PRACTICAL

STEP 2:-CODING
Private Sub Command1_Click()
Dim n(10) As Integer
Dim beg, end1, mid, taq As Integer
Print " entered values"
For i = 0 To 9
n(i) = Val(InputBox("enter no.")) 'entering value
Print n(i)
Next i
Print "search key"
sk = Val(InputBox("enter the search key"))
Print sk
For i = 0 To 9
'sorting element
For j = i + 1 To 9
If n(i) > n(j) Then
temp = n(j)
n(i) = n(j)
n(j) = temp
End If
Next j
Next i
beg = 0
end1 = 9
While beg <= end1
mid = (beg + end1) / 2
If sk = n(mid) Then
taq = taq + 1
GoTo label
End If
If sk < n(mid) Then
end1 = mid - 1
End If
If sk > n(mid) Then
beg = mid + 1
End If
Wend
label:
If taq > 0 Then
x = MsgBox("item found")
Else
x = MsgBox("item not found")
End If
End Sub

36

STEP 3:- OUTPUT

VB PRACTICAL

VB PRACTICAL

37

Q14. WAP TO SORT A DYNAMIC ARRAY OF


(A) N NUMBERS
Author name
Class
Unit No.
System No.
Path
Date
SOLUTIONS:STEP 1:- USING

Sn
o.
1

: Surabhi Roy
: BCA I
: II
: lab2,system11
: D:/Surabhi Vb Program/srt number
: 26/11/2011
INTERFACE AND PROPERTIES OF CONTROLS

Name of
the
Controls
Form 1

Property

Value

WindowState

2-maximized

Font

2
3
4

Label 1

Text 1
Command
1
5
Command
2
STEP 2:-CODING :

Font
Font
style
Font
size
Caption
Text
Caption
Caption

Dim a() general declaration


Dim b()
Private Sub Command1_Click()

Arial
Regular
12
Enter no. Of
arrays
Blank
Sort the
number
Exit

38

VB PRACTICAL

n = Val(Text1.Text)
ReDim a(n)
For i = 0 To n - 1
a(i) = Val(InputBox("enter element"))
Next i
For j = 0 To n - 1
For k = j + 1 To n
If a(j) > a(k) Then
x = a(j)
a(j) = a(k)
a(k) = x
End If
Next k
Next j
'printing sorted value
For i = 1 To n
Print a(i)
Next i
End Sub
Private Sub Command2_Click()
End
End Sub
STEP 3: OUTPUT :

39

VB PRACTICAL

40

VB PRACTICAL

(B) N STRINGS
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: II
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/string sort
Date
: 26/11/2011
SOLUTIONS:
STEP 1:USING INTERFACE AND PROPERTIES OF

Sn
o.
1

2
3
4

Name of
the
Controls
Form 1

Label 1

Text 1
Command
1
STEP 2:CODING :

Property

Value

Window state

2-maximized

Font

Arial
Regular

Font
Font
style
Font
size

Caption
Text
Caption

Private Sub Command1_Click()


Cls
s = Val(Text1.Text)
ReDim n(s)
ReDim n(1 To 9)
For i = 1 To s
n(i) = (InputBox("enter string"))
Next

12
Enter no. Of
arrays
Blank
Sort the string

CONTROLS

41

VB PRACTICAL

For i = 1 To 9
For j = 1 To 8
If n(j) > n(j + 1) Then
temp = n(j)
n(j) = n(j + 1)
n(j + 1) = temp
End If
Next j
Next i
For i = 1 To 9
Print n(i)
Next i
End Sub
STEP 3:- OUTPUT:

42

VB PRACTICAL

Q15. WAP TO TAKE INPUT OF TWO MATRICES AND PERFORM THEIR


ADDITION,SUBSTRACTION AND MULTIPLICATION USING MENU
EDITOR
Author name
Class
Unit No.
System No.
Path
Date
SOLUTIONS:STEP 1:- USING

Sn
o.
1

Name of
the
Controls
Form 1

: Surabhi Roy
: BCA I
: III
: lab2,system11
: D:/Surabhi Vb Program/string sort
: 05/12/2011
INTERFACE AND PROPERTIES OF

Property

Value

Windowstate

2maximized
Arial
Regular

Font

Font
Font
style
Font
size
Name
caption

12
Form1
Form1

CONTROLS

43

VB PRACTICAL

STEP 2:-CODING :
Dim n(3, 3), m(3, 3), t(3, 3), r, c As Integer general
declaration
Private Sub add_Click()
Print "******addition of matrix******"
For r = 0 To 2
For c = 0 To 2
t(r, c) = n(r, c) + m(r, c)
Next c
Next r
For r = 0 To 2 'print result
For c = 0 To 2
Print n(r, c),
Next c
Print
Next r
End Sub
Private Sub exit_Click()
End

44

VB PRACTICAL

End Sub
Private Sub matrix_Click()
Print ""
Print "******enter first matrix******"
For r = 0 To 2
'entering value for first matrix
For c = 0 To 2
m(r, c) = Val(InputBox("enter no."))
Next c
Next r
For r = 0 To 2 ' print first matrix
For c = 0 To 2
Print m(r, c),
Next c
Print
Next r
End Sub
Private Sub multiplication_Click()
Print "******multiplication of matrix******"
For r = 0 To 2
For c = 0 To 2
t(r, c) = 0
For z = 0 To 2
t(r, c) = t(r, c) + m(r, z) * n(z, c)
Next z
Next c
Next r
For r = 0 To 2 'print result
For c = 0 To 2
Print t(r, c),
Next c
Print
Next r
End Sub
Private Sub second_Click()
Print "******enter second matrix******"
For r = 0 To 2
'entering value for second matrix
For c = 0 To 2
n(r, c) = Val(InputBox("enter no."))
Next c
Next r
For r = 0 To 2 ' print second matrix
For c = 0 To 2
Print n(r, c),
Next c
Print
Next r

45

VB PRACTICAL

End Sub
Private Sub substract_Click()
Print "******substraction of matrix******"
For r = 0 To 2
For c = 0 To 2
t(r, c) = n(r, c) - m(r, c)
Next c
Next r
For r = 0 To 2 ' print first matrix
For c = 0 To 2
Print n(r, c),
Next c
Next r
For r = 0 To 2 'print second matrix
For c = 0 To 2
Print m(r, c),
Next c
Next r
For r = 0 To 2 'print result
For c = 0 To 2
Print n(r, c),
Next c
Print
Next r
End Sub

STEP 3:- OUTPUT

46

VB PRACTICAL

47

VB PRACTICAL

Q16.WAP TO ILLUSTRATE CALL BY VALUE AND CALL BY REFERENCE


Author name : Surabhi Roy
Class
: BCA I
Unit No.
: III
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/callby
Date
: 08/12/2011
SOLUTIONS:
STEP 1: USING INTERFACE AND PROPERTIES OF

Sn
o.
1

2
3

Name of
the
Controls
Form 1

Command
1
Command
2

Property

Value

Name
Caption
Window state
Font
Font
Font
style
Font
size
Name
Caption
Name
Caption

Form1
Form1
2-maximized
Arial
Regular
12
Command1
Call by value
Command2
Call by
reference

CONTROLS

48

VB PRACTICAL

STEP 2:CODING:
Dim a, b, temp As Integer general declaration
Private Sub Command1_Click()
a = 10
b = 20
Print
Print "call by value"
Print "Before swap first value = " & a & " and second value =" &
b
x = swap((a), (b))
Print "After swap first value = " & b & " and second value =" & a
End Sub
Private Function swap(ByVal x As Integer, ByVal y As Integer)
temp = x
x = y
y = temp
Print "during swap first value =" & x & " and second value=" & y
End Function
Private Sub Command2_Click()
a = 10
b = 20
Print
Print "call by referance"
Print "Before swap first value = " & a & " and second value =" &
b
x = swapref((a), (b))
Print "After swap first value = " & b & " and second value =" & a
End Sub
Private Function swapref(ByRef x As Integer, ByRef y As Integer)
temp = x
x = y
y = temp
Print "during swap first value =" & x & " and second value=" & y
End Function

STEP 3: OUTPUT :

49

Call by value
reference

VB PRACTICAL
Call by

50

VB PRACTICAL

Q17 WAP TO CALCULATE FACTORIAL OF A NUMBER USING USER


DEFINED FUNCTION.
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: III
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/factorial
Date
: 08/12/2011
SOLUTIONS:STEP 1: USING INTERFACE AND PROPERTIES OF

CONTROLS:

STEP 2:CODING :

Sn
o.
1

Name of
the
Controls
Form 1

Dim n As Integer general


declaration
Private Sub
Property
Value
cmdFACT_Click()
Name
caption
Window state
Font

Label 1

Text1

Text 2

Command
1

Font
Font
style
Font size
Name
Caption
Name
Text
Name
Text
Name
Caption

Command
2

name
Caption

Form1
Form1
2-maximized
Arial
Regular
12
Label1
Enter value
Text1
Blank
Text2
Blank
Command1
Factorial
value
Command2
Exit

51

VB PRACTICAL

Private Sub Command1_Click()


n = Val(Text1.Text)
f = fact(n)
Text2.Text = f
End Sub
Private Function fact(m As Integer)
If m = 1 Then
f = 1
Else
f = m * fact(m - 1)
End If
fact = f
End Function
Private Sub Command2_Click()
End
End Sub
STEP 3: OUTPUT:

VB PRACTICAL

52

Q18.TAKE INPUT OF AWORD AND WAP TP CHECK WHETHER IT IS A


PALINDROME OR NOT.
Author name
Class
Unit No.
System No.
Path
Date
SOLUTIONS:STEP 1:- USING

Sno
.
1

: Surabhi Roy
: BCA I
: III
: lab2,system11
: D:/Surabhi Vb Program/palindrome
: 08/12/2011
INTERFACE AND PROPERTIES OF

Name of
the
Controls
Form 1

Label 1

Text1

Command
1

Command
2
STEP 2:-CODING

Property

Value

Name
Caption
Window state
Font
Font
Font
style
Font
size
Name
Caption

Form1
Form1
2-maximized
Arial
Regular

Name
Text
Name
Caption

Text1
Blank
Command1
Palindrome
value
Command2
Exit

Name
Caption

12
Label1
Enter value

CONTROLS

53

VB PRACTICAL

Private Sub Command1_Click()


n = Text1.Text
'Entering string value
m = StrReverse(n)
'reversing the value
If StrComp(n, m) = 0 Then
'string comparison
MsgBox ("string is Palindrome") 'display result
Else
MsgBox ("string is not a palindrome")
'else part
End If
End Sub
Private Sub Command2_Click()
End
End Sub
STEP 3:- OUTPUT

54

VB PRACTICAL

Q19.WAP TO FIND SMALLEST AMONG GIVEN THREE NUMBERS USING USER DEFINED
PROCEDURES.

Author name : Surabhi Roy


Class
: BCA I
Unit No.
: II
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/smallest
Date
: 08/12/2011
SOLUTIONS:
STEP 1: USING INTERFACE AND PROPERTIES OF CONTROLS

55

VB PRACTICAL

STEP 2:-CODING
Sno
.
1

Name of
the
Controls
Form 1

Property

Value

2
3

Label 1
Label 2

Name
Caption
Window state
Fon
Font
Font style
t
Font size
Caption
Caption

Form1
Form1
2-maximized
Arial
Regular
12
Enter first no.
Enter second
no.
Enter third no.
Result
Blank
Blank
Blank
Blank
Smallest
number
Clear
Exit

4
5
6
7
8
9
10

Label 3
Label 4
Label 5
Text 1
Text 2
Text 3
Command 1

Caption
Caption
Caption
Text
Text
Text
Caption

11
Command 2
Caption
12
Command 3
Caption
Label4.Caption = m
End Sub
Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
Call mini(a, b, c)
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Label4.Caption = ""
End Sub
Private Sub Command3_Click()
End

Sub mini(a
As Integer,
b As
Integer, c
As Integer)
Dim m As
Integer
If (a <
b) Then
m =
a
Else
m =
b
End If
If
(m > c)
Then
m = c
End
If

56

End Sub
STEP 3:- OUTPUT

VB PRACTICAL

VB PRACTICAL

57

Q20. WAP TO GENERATE,PRINT AND FIND SUM OF FIRST N


ELEMENTS OF FIBONACCI SERIES USING RECURSION
Author name
Class
Unit No.
System No.
Path
Date

: Surabhi Roy
: BCA I
: II
: lab2,system11
: D:/Surabhi Vb Program/fibonacci
: 08/12/2011

SOLUTIONS:STEP 1:- USING INTERFACE AND PROPERTIES OF

Sno
.
1

Name of
the
Controls
Form 1

Listbox

Textbox

Textbox

Command

Property

Value

Name
Caption
Window state
Font
Font
Font
style
Font size
Name
Caption

Form1
Form1
2-maximized
Arial
Regular

Name
Text
Name
Text
Name
Caption

Text1
Blank
Text2
Blank
Command1
Fibbonacci
series

12
List1
Blank

CONTROLS

58

VB PRACTICAL

STEP 2:-CODING
Private Sub command1_Click()
List1.Clear
LIMIT = Val(Text1.Text)
Sum = 0
Dim I As Integer
Dim OVAL As Integer, NVAL As Integer, FVAL As Integer
I = 1
OVAL = 0
NVAL = 1
List1.AddItem OVAL
List1.AddItem NVAL
Do While I < LIMIT - 1
Sum = Sum + FVAL + NVAL
FVAL = OVAL + NVAL
List1.AddItem FVAL
OVAL = NVAL
NVAL = FVAL
I = I + 1
Loop
Text2.Text = Sum
End Sub
STEP 3:- OUTPUT

59

VB PRACTICAL

Q21. WAP TO PERFORM READ WRITE OPERATION IN SEQUENTIAL


FILE.
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: IV
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/filehandling
Date
: 10/12/2011
Solution :
Step-1 : User Interface & Properties of the Controls

Sequential Write
Sequential Read
SNo
1.

Name of the
Property
Control
Form
Name
Caption

2.

Frame

3.

Label

4.

Label

5.

Label

6.

Label

7.

Command

Window
State
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name

Value
Form1
Sequential File :
Writing Data
2-Maximized
Frame1
Student Data
Label1
Label1
Label2
Roll No.
Label3
Name
Label4
Student Fee
Command1

60

VB PRACTICAL

button
8.

SN
o
1.

Command
button

Name of the
Control
Form

2.

Frame

3.

Label

4.

Label

5.

Label

6.

Label

7.

Command
button

8.

Command
button

Caption
Name

Write
Command 2

Caption

Read File

Property
Name
Caption
Window
State
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name

Value
Form1
Sequential File
Handling : Read
2-Maximized
Frame1
Student Data
Label1
Label1
Label2
Roll No.
Label3
Name
Label4
Student Fee
Command1

Caption
Name

Read
Command 2

Caption

Exit

STEP 2: CODING:
SEQUENTIAL WRITEDim FSO As New FileSystemObject general declaration
Dim fileNm As File
Dim TS As TextStream
Private Sub cmdWrite_Click()
Call TS.WriteLine(Trim(StudNo.Text) & " " & Trim(StudName.Text) &
" " & Trim(StudFee.Text))
StudNo.Text = ""

61

VB PRACTICAL

StudName.Text = ""
StudFee.Text = ""
StudNo.SetFocus
End Sub
Private Sub Command1_Click()
Load frmSequential_Read
frmSequential_Read.Visible = True
End Sub
Private Sub Form_Load()
Call FSO.CreateTextFile("C:\data.dat")
Set fileNm = FSO.GetFile("c:\data.dat")
Set TS = fileNm.OpenAsTextStream(ForWriting)
lblFileName.Caption = fileNm.Path
End Sub
Private Sub Form_Terminate()
Call TS.Close
End Sub
SEQUENTIAL READ
Dim FSO As New FileSystemObject general declaration
Dim fileNm As File
Dim TS As TextStream
Private Sub cmdRead_Click()
Dim anystr As String
On Error GoTo handler
anystr = TS.ReadLine
Dim marks1, marks2 As Integer
'Retrieving StudentNo
mark1 = InStr(anystr, " ")
StudNo.Text = LTrim(Mid$(anystr, 1, mark1 - 1))
'Tracing the next blank space & retreiving student Name
mark2 = InStr(mark1 + 1, anystr, " ")
StudName.Text = Trim$(Mid$(anystr, mark1 + 1, (mark2 - mark1)))
'Retrieving Fee
StudFee.Text = Format$(Mid$(anystr, mark2 + 1, Len(anystr)),
"Currency")
Exit Sub
handler:
If Err.Number = 62 Then 'EOF Error
Call TS.Close
cmdRead.Enabled = False
Label2.Caption = " "
End If
End Sub

62

VB PRACTICAL

Private Sub Command1_Click()


End
End Sub
Private Sub Form_Load()
Set fileNm = FSO.GetFile("C:\data.dat")
Set TS = fileNm.OpenAsTextStream(ForReading)
Label2.Caption = fileNm.Path
End Sub
STEP 3:- OUTPUT
Sequential Write

Sequential Read

63

VB PRACTICAL

Q21. Create A User Defined Data Type Having Fields Name(As String
Of Length 20 Bytes), Rollno (As Integer),Class(As String Of 10
Bytes). Wap To Create A Random Access File To Store Above Data
And Perform Following Operations In This File.
(A)Write New Record (B) Read/Display Existing Record (C)Delete
Any Record (D)Search Any Record (E) List Selected Records (F)
Close The File
Author name
Class
Unit No.
System No.
Path
Date

: Surabhi Roy
: BCA I
: IV
: lab2,system11
: D:/Surabhi Vb Program/filehandling
: 10/12/2011

Solution :
Step-1 : User Interface & Properties of the Controls

64

VB PRACTICAL

65

Sn
o.
1

Name of
the
Controls
Form 1

VB PRACTICAL
Property

Value

Window state

2-maximized

Font

Arial
Regular

Font
Font
style
Font size

Caption

12
File handling :
random
(writing)
Dlgopen

Common
dialog
control
Command
1

Name

Command
2

Caption

Click here to
create a
random file
Exit

Sn
o.

Name of
the
Controls
Form 1

Property

Value

Window state

2-maximized

Font

Arial
Regular

Caption

Caption

3
4

Common
dialog
control
Command
1
Command

Name

Font
Font
style
Font size

12
File handling :
random
(writing)
Dlgopen

Caption

Select a file

Caption

Add record

66

5
6
7
8
9
10
11
12
13
14

Sn
o.
1

2
Command
3
Command
4
Label 1
Label 2
Label 3
Label 4
Text 1
Text 2
Text 3
Text 4

Name of
the
Controls
Form 1

VB PRACTICAL

Caption

Done

Caption

Read record

Caption
Caption
Caption
Caption
Text
Text
Text
Text

Student no
First name
Last name
Fee
Blank
Blank
Blank
Blank

Property

Value

Window state

2-maximized

Font

Arial
Regular

Caption
2

3
4
5
6
7
8
9
10
11
12

Common
dialog
control
Command 1
Command 2
Command 3
Label 1
Label 2
Label 3
Label 4
Text 1
Text 2
Text 3

Name

Caption
Caption
Caption
Caption
Caption
Caption
Caption
Text
Text
Text

Font
Font
style
Font
size

12
File handling :
random (read)
Dlgopen

Select a file
Next record
Done
Student no
First name
Last name
Fee
Blank
Blank
Blank

67

13
Text 4
STEP 2:- CODING:-

VB PRACTICAL
Text

Blank

Random Initialization
Dim CCJStud As studentrecord
Private Type studentrecord
StudentNumber As Integer
FirstName As String * 15
LastName As String * 15
Fee As Currency
End Type
Private Sub cmdExit_Click()
Me.Visible = False
frmRandomWrite.Visible = True
End Sub
Private Sub cmdInitialize_Click()
Dim recordlength As Long, ctr As Integer
Dim filename As String
recordlength = LenB(CCJStud)
dlgOpen.ShowOpen
filename = dlgOpen.filename
If dlgOpen.filename <> "" Then
Open filename For Random Access Write As #1 Len =
recordlength
For ctr = 1 To 2
Put #1, ctr, CCJStud
Next
Close #1
cmdInitialize.Enabled = False
MsgBox ("File Initialized. Click Exit to Terminate")
Else
MsgBox ("You must specify a file name")
End If
End Sub
Random Write
Option Explicit
Private Type studentrecord
StudNo As Integer
FirstName As String * 15
LastName As String * 15
fees As Currency
End Type
Dim CCJStud As studentrecord
Dim ctr As Integer
Private Sub cmdDone_Click()

68

VB PRACTICAL

Close #1
cmdOpenfile.Enabled = True
cmdEnter.Enabled = False
cmdDone.Enabled = False
End Sub
Private Sub cmdEnter_Click()
ctr = ctr + 1
CCJStud.StudNo = Val(txtNo.Text)
CCJStud.FirstName = txtFirstName.Text
CCJStud.LastName = txtLastName.Text
CCJStud.fees = Val(txtFee.Text)
Put #1, ctr, CCJStud
Call clearfields
End Sub
Private Sub clearfields()
txtNo.Text = ""
txtFirstName.Text = ""
txtLastName.Text = ""
txtFee.Text = ""
txtNo.SetFocus
End Sub
Private Sub cmdOpenfile_Click()
Dim recordlength As Long
Dim filename As String
recordlength = LenB(CCJStud)
dlgOpen.ShowOpen
filename = dlgOpen.filename
If dlgOpen.FileTitle <> " " Then
Open filename For Random Access Write As #1 Len =
recordlength
cmdOpenfile.Enabled = False
cmdEnter.Enabled = True
cmdDone.Enabled = True
Else
MsgBox ("You must specify a file name")
End If
End Sub
Private Sub Command1_Click()
frmRandomRead.Show
End Sub
Private Sub Form_Load()
ctr = 0
cmdEnter.Enabled = False
cmdDone.Enabled = False
End Sub
Private Sub Form_Terminate()

69

VB PRACTICAL

Close #1
End Sub
Random Read
Option Explicit
Private Type studentrecord
StudNo As Integer
FirstName As String * 15
LastName As String * 15
fees As Currency
End Type
Dim CCJStud As studentrecord
Dim ctr As Integer
Private Sub cmdDone_Click()
Close #1
cmdOpenfile.Enabled = True
cmdNext.Enabled = False
cmdDone.Enabled = False
txtNo.Text = ""
txtFirstName.Text = ""
txtLastName.Text = ""
txtFee.Text = ""
End Sub
Private Sub cmdNext_Click()
'Read record from a file
Do
Get #1, , CCJStud
Loop Until EOF(1) Or CCJStud.StudNo <> 0
If EOF(1) Then
cmdNext.Enabled = False
Exit Sub
End If
If CCJStud.StudNo <> 0 Then
txtNo.Text = Str$(CCJStud.StudNo)
txtFirstName.Text = CCJStud.FirstName
txtLastName.Text = CCJStud.LastName
txtFee.Text = Str$(CCJStud.fees)
End If
End Sub
Private Sub cmdOpenfile_Click()
Dim recordlength As Long
Dim filename As String
recordlength = LenB(CCJStud)
dlgOpen.ShowOpen
filename = dlgOpen.filename
If dlgOpen.FileTitle <> " " Then

70

VB PRACTICAL

Open filename For Random Access Read As #1 Len = recordlength


cmdOpenfile.Enabled = False
cmdNext.Enabled = True
cmdDone.Enabled = True
Else
MsgBox ("You must specify a file name")
End If
End Sub
Private Sub Form_Load()
cmdNext.Enabled = False
cmdDone.Enabled = False
End Sub
Private Sub Form_Terminate()
Close #1
End Sub
STEP 3:- OUTPUT

Random(Initialize)

Random(Write)

71

VB PRACTICAL

Random(Read)

Q23. WAP TO DISPLAY RECORDS OF A TABLE USING DAO TO MOVE AT


FIRST RECORD, NEXT RECORD, PREVIOUS RECORDS, LAST RECORDS
IN THE TABLE.
Author name
Class
Unit No.
System No.
Path
Date
Solution :

: Surabhi Roy
: BCA I
: V
: lab2,system11
: D:/Surabhi Vb Program/adodc
: 21/12/2011

Step-1 : User Interface & Properties of the Controls

72

Sno
1.

Name of the
control
Form

2.

Label

3.

Label

4.

Label

5.

Textbox

6.
Textbox
7.
Textbox
8.
Datatool

9.

Commandbutt
on

10.

Commandbutt
on

VB PRACTICAL

Property

Value

Name
Caption
Windowstate
Name
Caption
Name
Caption
Name
Caption
Name
Data source

Form1
Data tool
2-maximized
Label1
Enter name
Label2
Enter class
Label3
Enter roll no
Text1
Data1

Data field

Name

Data field
Name
Data source
Data field
Name
Connect
Database

Class
Text2
Data1
Roll no
Text3
Access
D:\jyoti\stud_i
nfo
Student
information
Command1
Add new
Command1
Update
Command1
Edit

Record
source
Name
Caption
Name
Caption
Name
Caption

73

11.

12.

Commandbutt
on
Commandbutt
on

Commandbutt
on
13. Commandbutt
on
STEP 2: CODING:

VB PRACTICAL
Name
Caption
Name
Caption
Name

Command1
delete
Command1
Previous
Command1

Caption
Name
Name
Caption

Next
Command 1
Command1
Next

Private Sub Command1_Click()


Data1.Recordset.AddNew
End Sub
Private Sub Command2_Click()
Data1.Recordset.Update
End Sub
Private Sub Command3_Click()
Data1.Recordset.Edit
End Sub
Private Sub Command4_Click()
Data1.Recordset.Delete
End Sub
Private Sub Command5_Click()
Data1.Recordset.MovePrevious
End Sub
Private Sub Command6_Click()
Data1.Recordset.MoveNext
End Sub
Private Sub Command7_Click()
End
End Sub
STEP 3:- OUTPUT

74

VB PRACTICAL

75

VB PRACTICAL

Q24. CREATE A TABLE USING VISUAL DATA MANAGER AND WRITE A


PROGRAM USING ADO AND ADVANCED BOUND CONTROL TO
ADD,EDIT,DELETE,& NAVIGATE RECORDS.
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: V
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/adodc
Date
: 21/12/2011
Solution :
Step-1 : User Interface & Properties of the Controls

Sno

1.

Name of
the
control
Form

2.

Label

3.

Label

4.

Label

5.

Label

6.

Label

7.

Textbox

Property

Value

Name
Caption
Windowstate
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Data source

Form1
Data tool
2-maximized
Label1
Enter rollno
Label2
Enter name
Label3
Enter class
Label4
Result
Label5
Percent
Text1
Adodc1

VB PRACTICAL

76

8.

Textbox

9.

Textbox

10.

Textbox

11.

Textbox

12.

Datatool

Data field
Name
Data source
Data field
Name
Data source
Data field
Name
Data source
Data field
Name
Data source
Data field
Name
Connect
Database
Record source

13.
14.
15.
16.
17.
18.

Commandb
utton
Commandb
utton
Commandb
utton
Commandb
utton
Commandb
utton
Commandb
utton

Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Caption

Rollno
Text2
Adodc1
Name
Text3
Adodc1
Class
Text4
Adodc1
Result
Text5
Adodc1
Percent
Adodc1
Access
D:\jyoti\stud_inf
o
Student
information
Command1
Append
Command1
Edit
Command1
Delete
Command1
Move previous
Command1
Move next
Command1
Exit

STEP 2:- CODING:Private Sub Command1_Click()


ADODC1.Recordset.AddNew
End Sub
Private Sub Command2_Click()
ADODC1.Recordset.Edit
End Sub
Private Sub Command3_Click()
ADODC1.Recordset.Delete
If ADODC1.Recordset.EOF = True Then
ADODC1.Recordset.MoveFirst
Else
ADODC1.Recordset.MoveNext
End If

77

VB PRACTICAL

End Sub
Private Sub Command4_Click()
If ADODC1.Recordset.BOF = True Then
ADODC1.Recordset.MoveLast
Else
ADODC1.Recordset.MovePrevious
End If
End Sub
Private Sub Command5_Click()
If ADODC1.Recordset.EOF = True Then
ADODC1.Recordset.MoveFirst
Else
ADODC1.Recordset.MoveNext
End If
End Sub
Private Sub Command6_Click()
End
End Sub
STEP 3:- OUTPUT

Q25. WAP TO ACCESS A DATABASE USING ADO & DISPLAY A KEY


COLUMN IN THE COMBOBOX OR LIST BOX WHEN AN ITEM IS

78

VB PRACTICAL

SELECTED IN IT, IT CORRESPONDING RECORDS IS SHOWN IN MSH


FLEX GRID
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: V
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/ado
Date
: 21/12/2011
Solution :
Step-1 : User Interface & Properties of the Controls

SN
o.
1.

Name of the
Control
Form

2.

Label

Label

Label

Label

6
Textbox
7.
Textbox
8.
Textbox
9.
ComboBox
STEP 2:- CODING-

Property

Value

Name
Caption
Windowstate
Name
Caption
Name
Caption
Name
Caption
Name
Caption
Name
Name
Name
Name

Form1
MSH GRID
2-Maximized
Label1
Select rollno.
Label2
Name
Label3
Class
Label4
Percent
Text1
Text
Text
Combo1

Dim db As Database general declaration


Dim RS As Recordset
Private Sub Combo1_click()
X = "SELECT*FROM STUDENT_INFO WHERE ROLLNO=" & Combo1.Text
Set RS = db.OpenRecordset(X)
Text1.Text = RS!Name
Text2.Text = RS!Class
Text3.Text = RS!Percent
End Sub
Private Sub Form_Load()
Set db = OpenDatabase("D:\POOJA\VB\STUDENT_INFO.MDB")
Set RS = db.OpenRecordset("SELECT*FROM STUDENT_INFO")

79

VB PRACTICAL

Do Until RS.EOF
Combo1.AddItem RS!ROLLNO
RS.MoveNext
Loop
End Sub
STEP 3:- OUTPUT

Q26. WAP to generate marksheet of students in a class through data


report.

80

VB PRACTICAL

Author name : Surabhi Roy


Class
: BCA I
Unit No.
: V
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/data report
Date
: 21/12/2011
Solution :
Step-1 : User Interface & Properties of the Controls
Data environment :
1. To add data environment into the go to project menu and
select add data environment

2.In the project explorer window select data environment and


right click on it click on a add then data Report.

3. Double

click on Data
Environment 1
it will then display the menu of data environment on that click
on connection1 and select its properties.(figure)

81

VB PRACTICAL

4. Connection property window will display the window for data


link (figure) from where we have to link our database. Select
Microsoft jet 3.5.0 OLD EB Provider now click on next button

5.We have to sepecify the connection to data access. Select the


data base name

and then click on test connection button. If the connection is


properly connected to our ACCESS database then it will display
the dialog box as text connection succeded.(figure)

82

VB PRACTICAL

6.Once all we have done then click OK on Data Link dialog box and
again in property page dialog.
Now right click on
connection 1
then Add command
then properties
Command property table display

Database table object


Object Name
click on apply then ok.
DATA REPORT
Now select data report

form.

Table
Our database name {Employee
detail}

83

VB PRACTICAL

And drag and drop the child control i.e. command1 into the data
report
form as it appear on the screen. Now give the heading
or any other detail as we like it to be appear on the windows .
Now go to the property window of the dataReport1 form and change
its property as

84

VB PRACTICAL

9.After all is done save the form and create the start up object
as our
default form name click apply then.

10. Run the form by clicking (f5) or by clicking start from the
tool bar. It will display the form in this way.
STEP 3:- OUTPUT

85

VB PRACTICAL

Q27. WAP TO ILLUSTRATE VARIOUS KEYBOARD AND MOUSE EVENTS.


Author name : Surabhi Roy
Class
: BCA I
Unit No.
: V
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/mouse event
Date
: 21/12/2011
Solution :
Step-1 : User Interface & Properties of the Controls

Sn
o.
1

Name of
the
controls
Form 1

Property

Value

Name
Caption
Window
state
Font
Font

Form 1
Form1
2-maximized

Font
style
Font
size
2

Command

Name

Times new
roman
Bold italic
14
Command1

86

VB PRACTICAL
Caption

Clear

STEP 2:- CODINGOption Explicit


Private Sub Command1_Click()
Call Cls
End Sub
Private Sub Form_Click()
'Randomly set form forecolor
Select Case (1 + Int(Rnd() * 4))
Case 1
ForeColor = vbBlack
Case 1
ForeColor = vbMagenta
Case 1
ForeColor = vbRed
Case 1
ForeColor = vbBlue
End Select
End Sub
Private Sub Form_DblClick()
'Randomly set form backcolor
Select Case (1 + Int(Rnd() * 4))
Case 1
ForeColor = vbWhite
Case 1
ForeColor = vbYellow
Case 1
ForeColor = vbGreen
Case 1
ForeColor = vbCyan
End Select
'change chkmove backcolor to form's back color
chkmove.BackColor = BackColor
End Sub
Private Sub Form_Load()
Call Randomize
'Randomize
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
CurrentX = X
CurrentY = Y
Print " hello "
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)

87

VB PRACTICAL

'If checked enabled printing operation


' If checkmove.Value = 1 Then
CurrentX = X
CurrentY = Y
Print " hello "
'End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
CurrentX = X
CurrentY = Y
Print " hello "
End Sub

STEP 3:OUTPUT:

VB PRACTICAL

88

Q28. USING DRIVE ,DIRECTORY AND FILE LIST BOX(IT WILL SHOW
ONLY BMP FILES). LET THE USER SELECT THE BMP FILES, WHICH
WILL APPEAR IN PICTURE BOX AS USER CLICK ON ANY ITEM IN THE
LIST BOX.
Author name
Class
Unit No.
System No.
Path
Date

: Surabhi Roy
: BCA I
: V
: lab2,system11
: D:/Surabhi Vb Program/bmp
: 03/01/2012

Solution :
Step-1 : User Interface & Properties of the Controls

Sno

1.
2.
3.
4.
5.

Name of
the
control
Form
Drivelistbox
Dirlistbox
Filelistbox
Commandbut
ton

Property

Value

Name
Caption
Window state
Name
Name
Name
Name

Form1
Directory
2-maximized
Drive1
Dir1
File1
Show

Caption

Show

89

6.

Commandbut
ton

VB PRACTICAL
Name

Command2

Caption

Exit

STEP 2:- CODINGPrivate Sub Command2_Click()


End
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub Show_Click()
Dim s As String
s = File1.Path + "\" + File1.FileName
Picture1.Picture = LoadPicture(s)
End Sub
STEP 3:- OUTPUT

90

VB PRACTICAL

Q29. USING TOOLBAR DESIGN AN INTERFACE FOR STRING


MANIPULATION. TOOLBAR SHOULD HAVE TABLE
FIND (A)LENGTH OF STRING
(B) NO. OF BLANK SPACES IN STRING
(C) REVERSE THE STRING ALSO SHOW CURRENT DATE & TIME IN
STATUS BAR.
Author name : Surabhi Roy
Class
: BCA I
Unit No.
: V
System No. : lab2,system11
Path
: D:/Surabhi Vb Program/toolbar
Date
: 03/01/2012
Solution :
Step-1 : User Interface & Properties of the Controls

Sn
o
1.

Name of the
control
Form

2.

Toolbar

3.

Toolbar

4.

Toolbar

5.

Textbox

Property

Value

Name
Caption
Windowstate
Name
Caption
Name
Caption

Form1
Form9
2-maximized
Tool1
Length
Tool2
No. Blank
spaces
Tool3
Reverse
Text1

Name
Caption
Name

VB PRACTICAL

91

6.

Timer

7.

Label

Name
Interval
Name

Timer1
1
Label1

STEP 2:- CODINGPrivate Sub Timer1_Timer()


StatusBar1.SimpleText = Date$ + " " + Time$()
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As
MSComctlLib.Button)
Dim bl As Integer
Dim n As Integer
Dim s As String
s = Text1.Text
If Button.Index = 1 Then
Label1.Caption = Len(s)
End If
If Button.Index = 2 Then
n = Len(s)
Do While (n > 0)
If (Mid$(s, n, 1) = " ") Then
bl = bl + 1
End If
n = n - 1
Loop
Label1.Caption = bl
End If
If (Button.Index = 3) Then
Label1.Caption = ""
n = Len(s)
Do While (n > 0)
Label1.Caption = Label1.Caption + Mid$(s, n, 1)
n = n - 1
Loop
End If
End Sub
STEP 3:- OUTPUT

92

VB PRACTICAL

93

VB PRACTICAL

You might also like