Visual Basic Pratice Question and Answer
Visual Basic Pratice Question and Answer
VB PRACTICAL
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
STEP 3 :- OUTPUT :
ADDITION :
SUBTRACTION:
MULTIPLICATION
DIVISION
VB PRACTICAL
VB PRACTICAL
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
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
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
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
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:
3:OUTPUT:
VB PRACTICAL
19
Q7.
DIGITS,SPECIAL
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
VB PRACTICAL
21
STEP
3:-
OUTPUT
VB PRACTICAL
22
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
24
VB PRACTICAL
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
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
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
29
VB PRACTICAL
VB PRACTICAL
30
: Surabhi Roy
: BCA I
: III
: lab2,system11
: D:/Surabhi Vb Program/rocket
: 23/09/2011
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
32
VB PRACTICAL
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
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
VB PRACTICAL
VB PRACTICAL
37
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
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
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
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
46
VB PRACTICAL
47
VB PRACTICAL
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
CONTROLS:
STEP 2:CODING :
Sn
o.
1
Name of
the
Controls
Form 1
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
VB PRACTICAL
52
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
54
VB PRACTICAL
Q19.WAP TO FIND SMALLEST AMONG GIVEN THREE NUMBERS USING USER DEFINED
PROCEDURES.
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
: Surabhi Roy
: BCA I
: II
: lab2,system11
: D:/Surabhi Vb Program/fibonacci
: 08/12/2011
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
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
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
Random(Initialize)
Random(Write)
71
VB PRACTICAL
Random(Read)
: Surabhi Roy
: BCA I
: V
: lab2,system11
: D:/Surabhi Vb Program/adodc
: 21/12/2011
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
74
VB PRACTICAL
75
VB PRACTICAL
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
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
78
VB PRACTICAL
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
79
VB PRACTICAL
Do Until RS.EOF
Combo1.AddItem RS!ROLLNO
RS.MoveNext
Loop
End Sub
STEP 3:- OUTPUT
80
VB PRACTICAL
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
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
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
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
87
VB PRACTICAL
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
90
VB PRACTICAL
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
92
VB PRACTICAL
93
VB PRACTICAL