100% found this document useful (1 vote)
3K views

Program No-01 Aim: WAP To Perform Arithmetic Operation Using Command Button. Code

The document contains code for 5 programs written in Visual Basic. Program 1 allows arithmetic operations using command buttons for addition, subtraction, multiplication and division. Program 2 calculates simple and compound interest given principal, rate and time. Program 3 generates multiplication tables for a given number. Program 4 simulates a mark sheet to calculate grades based on marks input in 5 subjects. Program 5 creates a basic calculator application.

Uploaded by

manisha Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
3K views

Program No-01 Aim: WAP To Perform Arithmetic Operation Using Command Button. Code

The document contains code for 5 programs written in Visual Basic. Program 1 allows arithmetic operations using command buttons for addition, subtraction, multiplication and division. Program 2 calculates simple and compound interest given principal, rate and time. Program 3 generates multiplication tables for a given number. Program 4 simulates a mark sheet to calculate grades based on marks input in 5 subjects. Program 5 creates a basic calculator application.

Uploaded by

manisha Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 67

Department of Computer Science

Rungta College of Science & Technology, Durg

Program no-01
Aim: WAP to perform arithmetic operation using command button.
Code :
Dim a, b, c As Integer
Dim d, e, f As Double

Private Sub Command1_Click()


a = Val(InputBox("Enter any number", "Addition", 0))
b = Val(InputBox("Enter any number", "Addition", 0))
c=a+b
MsgBox (c)
End Sub

Private Sub Command2_Click()


a = Val(InputBox("Enter any number", "Subtraction", 0))
b = Val(InputBox("Enter any number", "Subtraction", 0))
c=a-b
MsgBox (c)
End Sub

Private Sub Command3_Click()


a = Val(InputBox("Enter any number", "Multiplication", 0))
b = Val(InputBox("Enter any number", "Multiplication", 0))
c=a*b
MsgBox (c)
End Sub

Private Sub Command4_Click()


d = Val(InputBox("Enter any number", "Division", 0))
e = Val(InputBox("Enter any number", "Division", 0))
f = (d / e)
MsgBox (f)
End

Lab Manual: CS-(Visual Basic)


Department of Computer Science
Rungta College of Science & Technology, Durg

Output :

2
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no-02
Aim: WAP to take of principal, rate & time and calculate simple interest & compound
interest

Code :

Dim p, r, t, si As Double
Dim a As String

Private Sub Command1_Click()


si = p * r * t / 100
Text4.Text = si
End Sub

Private Sub Text1_Change()


On Error Resume Next
a = Text1.Text
If a < 48 And a > 57 Then
MsgBox ("Invalid Entry,Insert only numbers")
Text1.Text = ""
End If
p = Val(a)
End Sub

Private Sub Text2_Change()


On Error Resume Next
a = Text2.Text
If a < 48 And a > 57 Then
MsgBox ("Invalid Entry,Insert only numbers")
Text2.Text = ""
End If
r = Val(a)
End Sub

Private Sub Text3_Change()


On Error Resume Next
a = Text3.Text
If a < 48 And a > 57 Then
3
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

MsgBox ("Invalid Entry,Insert only numbers")


Text3.Text = ""
End If
t = Val(a)
End Sub

Output :

4
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no-03
Aim: Write a program to take input of /X and print table of X in the following format

Code :

Dim a, b, x, y As Integer
Private Sub Command1_Click()
List1.Clear
a = Val(InputBox("Enter the number whose table you want to print", "Table", 1))
y = Val(InputBox("Upto which value you want to print table", "Mathematical Table", 10))
b=a
For x = 1 To y
List1.AddItem (b & " * " & x & " = " & a * x)
Next
End Sub

Output :

5
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no-04
Aim: Design an interface, which will appear like mark sheet. It will take input of
marks, in five subject and calculate total marks and percentage than provide grade
according to following criteria.

CODE :

Dim a As String
Dim m, p, c, e, h, b As Integer
Dim per As Double

Private Sub Cmd1()


per = (m + p + c + e + h) / 5
Text6.Text = per
If per >= 90 Then Text7.Text = "A+"
If per < 90 And per >= 75 Then Text7.Text = "A"
If per < 75 And per >= 60 Then Text7.Text = "B"
If per < 60 And per >= 45 Then Text7.Text = "C"
If per < 45 Then Text7.Text = "F"
If m > 35 And p > 35 And c > 35 And e > 35 And h > 35 Then
Text8.Text = "Pass"
Else
Text8.Text = "fail"
Text7.Text = "Nil"
End If
End Sub

Private Sub Text1_Change()


On Error Resume Next
a = Text1.Text
b = Val(Text1.Text)
If a < 48 And a > 57 Then
MsgBox ("Invalid Entry,Insert only numbers")
Text1.Text = ""
ElseIf b > 100 Then
MsgBox ("Invalid Input")
Text1.Text = ""
End If
6
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

m = Val(a)
Ankur
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then Text2.SetFocus
End Sub

Private Sub Text2_Change()


On Error Resume Next
a = Text2.Text
b = Val(Text2.Text)
If a < 48 And a > 57 Then
MsgBox ("Invalid Entry,Insert only numbers")
Text2.Text = ""
ElseIf b > 100 Then
MsgBox ("Invalid Input")
Text2.Text = ""
End If
p = Val(a)
Ankur
End Sub

Private Sub Text2_GotFocus()


If Text1.Text = "" Then Text1.SetFocus
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then Text3.SetFocus
End Sub

Private Sub Text3_Change()


On Error Resume Next
a = Text3.Text
b = Val(Text3.Text)
If a < 48 And a > 57 Then

7
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

MsgBox ("Invalid Entry,Insert only numbers")


Text3.Text = ""
ElseIf b > 100 Then
MsgBox ("Invalid Input")
Text3.Text = ""
End If
c = Val(a)
Ankur
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then Text4.SetFocus
End Sub

Private Sub Text4_Change()


On Error Resume Next
a = Text4.Text
b = Val(Text4.Text)
If a < 48 And a > 57 Then
MsgBox ("Invalid Entry,Insert only numbers")
Text4.Text = ""
ElseIf b > 100 Then
MsgBox ("Invalid Input")
Text4.Text = ""
End If
e = Val(a)
Ankur
End Sub

Private Sub Text4_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then Text5.SetFocus
End Sub

Private Sub Text5_Change()


On Error Resume Next
a = Text5.Text

8
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

b = Val(Text5.Text)
If a < 48 And a > 57 Then
MsgBox ("Invalid Entry,Insert only numbers")
Text5.Text = ""
ElseIf b > 100 Then
MsgBox ("Invalid Input")
Text5.Text = ""
End If
h = Val(a)
Ankur
End Sub

Private Sub view_Click()


End Sub

Private Sub Timer1_Timer()


StatusBar1.Panels(1).Text = Time
End Sub

Output :

9
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no-05
Aim: WAP to create a simpler calculator.

Code :
Dim num1, num2, result As Double
Dim ref, dec As Integer
Dim op As String

Private Sub Command1_Click(Index As Integer)


If dec = 0 And Val(Text1.Text) = 0 Then Text1.Text = ""
If ref = 0 Then
Text1.Text = Text1.Text & Command1(Index).Caption
Else
Text1.Text = Command1(Index).Caption
ref = 0
End If
End Sub
Private Sub Command10_Click()
Text1.Text = 0
num1 = 0
num2 = 0
result = 0
ref = 0
dec = 0
End Sub

Private Sub Command2_Click()


If dec = 0 Then
Text1.Text = Text1.Text & Command2.Caption
End If
dec = 1
End Sub

Private Sub Command3_Click()


On Error GoTo l1
num2 = Val(Text1.Text)
ref = 1

10
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Select Case op
Case "*"
result = num1 * num2
Case "/"
result = num1 / num2
Case "+"
result = num1 + num2
Case "-"
result = num1 - num2
End Select
Text1.Text = result
If Err.Number = 11 Then
Text1.Text = "Division By Zero"
End If
End Sub
Private Sub Command4_Click()
If num1 <> 0 Then
Command3_Click
End If
op = "+"
num1 = Val(Text1.Text)
ref = 1
dec = 0
End Sub

Private Sub Command5_Click()


If num1 <> 0 Then
Command3_Click
End If
op = "-"
num1 = Val(Text1.Text)
ref = 1
dec = 0
End Sub
Private Sub Command6_Click()
If num1 <> 0 Then

11
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Command3_Click
End If
op = "*"
num1 = Val(Text1.Text)
ref = 1
dec = 0
End Sub

Private Sub Command7_Click()


If num1 <> 0 Then
Command3_Click
End If
op = "/"
num1 = Val(Text1.Text)
ref = 1
dec = 0
End Sub

Private Sub Command8_Click()


ref = 1
Text1.Text = Val(Text1.Text) ^ 0.5
dec = 0
End Sub

Output :

12
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no-06
Aim: Write a program to check whether an entered no. is prime or not.
Code :
Dim a, x As Integer
Dim b As String

Private Sub Command1_Click()


For x = 2 To a - 1
If a Mod x = 0 Then
MsgBox ("Entered Number is not Prime")
Exit For
End If
Next
If x = a Then
MsgBox ("Entered Number is Prime")
End If
End Sub
Private Sub Text1_Change()
On Error Resume Next
b = Text1.Text
If b < 48 And b > 57 Then
MsgBox ("Insert only numbers")
Text1.Text = ""
End If
a = Val(b)
End Sub

Output :

13
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no-07
Aim: Write a program which will count all vowels, consonanants, digits, special
character and blank spaces in a sentence.

Code :

Dim ac, ASC1, vo, co, di, sc, bs, nl As Integer


Dim S As String

Private Sub Text1_KeyPress(KeyAscii As Integer)


ASC1 = ac
ac = KeyAscii
Select Case ac
Case 65, 69, 73, 79, 85, 97, 101, 105, 111, 117
vo = vo + 1
GoTo L1
Case 65 To 90, 97 To 122
co = co + 1
Case 48 To 57
di = di + 1
Case 32
bs = bs + 1
GoTo L1
Case 13
nl = nl + 1
GoTo L1
Case Else
sc = sc + 1
End Select
L1:
Text2.Text = vo
Text3.Text = co
Text4.Text = di
Text5.Text = sc
Text6.Text = bs
Text7.Text = nl
End Sub

14
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Output :

15
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no-08
Aim: WAP to illustrate all functionalities of list box and combo box.

Code :

Private Sub Command1_Click()


Dim n As Integer
For n = 0 To List1.ListCount - 1
If List1.Selected(n) = True Then
List2.AddItem List1.List(n)
List1.Selected(n) = False
End If
Next n
End Sub

Private Sub Command2_Click()


Dim I, j As Integer
For I = (List2.ListCount - 1) To j Step -1
If List2.Selected(I) = True Then
List2.RemoveItem (I)
List2.SetFocus
End If
Next I
If List2.ListCount < 1 Then
Command2.Enabled = False
Command1.Enabled = False
List1.SetFocus
End If
End Sub

Private Sub Command3_Click()


Dim I As Integer
For I = 0 To List1.ListCount - 1 Step 1
If List1.Selected(I) Then
MsgBox "You have selected " & List1.List(I)
End If
Next I
16
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

End Sub

Private Sub Command5_Click()


Unload Me
End Sub

Private Sub Form_Load()


List1.AddItem "Color"
List1.AddItem "Red"
List1.AddItem "Black"
List1.AddItem "Green"
List1.AddItem "Blue"
List1.AddItem "White"
List1.AddItem "Yellow"
End Sub

Private Sub List1_Click()


Command1.Enabled = True
End Sub

Private Sub List2_Click()


Command2.Enabled = True
End Sub

17
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Output :

Adding Items To List 2

18
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no-09
Aim: WAP using check boxes for following font effects.
a) Bold
b) Italic
c) Underline
d) Increase font size
e) Decreases font size
f) Font color

Code :

Private Sub Check1_Click()


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

Private Sub Check2_Click()


If Check2.Value = 1 Then
Text1.FontItalic = True
Else
Text1.FontItalic = False
End If
End Sub

Private Sub Check3_Click()


If Check3.Value = 1 Then
Text1.FontUnderline = True
Else
Text1.FontUnderline = False
End If
End Sub

Private Sub Command1_Click()


Text1.Text = ""
End Sub
19
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Private Sub Option1_Click()


Text1.ForeColor = vbRed
End Sub

Private Sub Option2_Click()


Text1.ForeColor = vbBlue
End Sub

Private Sub Option3_Click()


Text1.ForeColor = vbGreen
End Sub

Private Sub Option4_Click()


Text1.FontSize = 8
End Sub

Private Sub Option5_Click()


Text1.FontSize = 10
End Sub

Private Sub Option6_Click()


Text1.FontSize = 12
End Sub

Private Sub Option7_Click()


Text1.FontSize = 14
End Sub

Private Sub Option8_Click()


Text1.FontSize = 16
End Sub

Private Sub Option9_Click()


Text1.ForeColor = vbYellow
End Sub

20
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Output :

21
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no-10
Aim: WAP for temperature conversion using option button.

Code :
Dim X As String
Dim a As Double
Dim fr1, fr2 As Integer

Private Sub Convert()


If Option1.Value = True Then
fr1 = 1
ElseIf Option2.Value = True Then
fr1 = 2
ElseIf Option3.Value = True Then
fr1 = 3
End If
If Option6.Value = True Then
fr2 = 1
ElseIf Option5.Value = True Then
fr2 = 2
ElseIf Option4.Value = True Then
fr2 = 3
End If
Select Case fr1
Case 1
Select Case fr2
Case 1
Text2.Text = a
Case 2
Text2.Text = ((9 * a) + 160) / 5
Case 3
Text2.Text = a + 273
End Select
Case 2
Select Case fr2
Case 1
22
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Text2.Text = ((5 * a) - 160) / 9


Case 2
Text2.Text = a
Case 3
Text2.Text = ((5 * a) + 2297) / 9
End Select
Case 3
Select Case fr2
Case 1
Text2.Text = a - 273
Case 2
Text2.Text = (9 * (a - 273) / 5) + 32
Case 3
Text2.Text = a
End Select
End Select
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As


Single)
Convert
End Sub

Private Sub Frame1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As


Single)
Convert
End Sub

Private Sub Frame2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As


Single)
Convert
End Sub

Private Sub Option1_Click()


Convert
End Sub

23
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Private Sub Option2_Click()


Convert
End Sub

Private Sub Option3_Click()


Convert
End Sub

Private Sub Option4_Click()


Convert
End Sub

Private Sub Option5_Click()


Convert
End Sub

Private Sub Option6_Click()


Convert
End Sub

Private Sub Text1_Change()


On Error Resume Next
X = Text1.Text
If X < 46 And X > 57 Or X = 47 Then
MsgBox ("Invalid Input")
Text1.Text = ""
End If
a = Val(X)
Convert
End Sub

24
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Output :

Program no11 : WAP to launch a rocket using picture box and timer control.

Code :

Private Sub Command1_Click()


On Error Resume Next
VScroll1.Value = Min
Picture1.Top = 10680
Timer1.Interval = 0
End Sub

Private Sub Command2_Click()


Timer1.Interval = 10
End Sub

Private Sub Form_Load()


Text1.Text = VScroll1.Value
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As


Single)
Text1.Text = VScroll1.Value
End Sub

Private Sub Timer1_Timer()


Picture1.Top = Picture1.Top - VScroll1.Value
End Sub

Private Sub VScroll1_Change()


Text1.Text = VScroll1.Value
End Sub

Output :

25
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no12 : WAP to change back color of any control (label, textbox)using scroll
box.

Form :

Code :

Private Sub Command1_Click()


HScroll1.Value = 0
26
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

HScroll3.Value = 0
HScroll4.Value = 0
End Sub

Private Sub HScroll1_Change()


Label1.BackColor = RGB(HScroll1.Value, HScroll3.Value, HScroll4.Value)
Text4.Text = HScroll1.Value / 255 * 100
End Sub

Private Sub HScroll3_Change()


Label1.BackColor = RGB(HScroll1.Value, HScroll3.Value, HScroll4.Value)
Text2.Text = HScroll3.Value / 255 * 100
End Sub

Private Sub HScroll4_Change()


Label1.BackColor = RGB(HScroll1.Value, HScroll3.Value, HScroll4.Value)
Text3.Text = HScroll4.Value / 255 * 100
End Sub

Private Sub Text1_Change()


Text1.Text = HScroll4.Value
End Sub

Output :

27
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no13 : WAP to search an element for a one dimension static array.

Form :

Code :

Dim a(10), b As Integer


Private Sub Command1_Click()
For i = 0 To 9
a(i) = InputBox("enter any number")
Next i
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then
b = Val(Text1.Text)
For i = 0 To 9
If b = a(i) Then
x = MsgBox("The position of entered number in entered array is" & i, vbOKOnly,
"Search Result")
Exit Sub
End If
Next i
x = MsgBox("Element not found", vbOKOnly, "Message")
End If
End Sub

28
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Output :

29
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no14 : WAP to sort a dynamic array of N numbers and N strings (input
array size at run time).

For m :

Code :

Dim A() As String


Dim B() As Integer
Dim I As Integer
Dim R As Integer
Dim J As Integer
Dim TEMP As Variant

Private Sub Command1_Click()


R = Val(InputBox("Enter The Range"))
ReDim A(R) As String
For I = 1 To R Step 1
A(I) = InputBox("Enter The Strings")
Next I
End Sub

Private Sub Command2_Click()


R = Val(InputBox("Enter The Range"))
ReDim B(R) As Integer
30
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

For I = 0 To R - 1
B(I) = Val(InputBox("Enter The Integers"))
Next I
End Sub

Private Sub Command3_Click()


For I = 1 To R Step 1
For J = 1 To R - I Step 1
If A(J + 1) < A(J) Then
TEMP = A(J)
A(J) = A(J + 1)
A(J + 1) = TEMP
End If
Next J
Next I
Print "The Sorted Strings Are : -"
Print
For I = 1 To R Step 1
Print A(I)
Next I
End Sub

Private Sub Command4_Click()


For I = 0 To R - 2
For J = 0 To (R - 2) - I
If B(J) < B(J + 1) Then
TEMP = B(J)
B(J) = B(J + 1)
B(J + 1) = TEMP
End If
Next J
Next I
For I = 0 To R - 1
Print B(I)
Next
End Sub

Private Sub Command5_Click()


Unload Me
End Sub

Output :

31
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no15 : WAP to take input of two matrices and perform their addition
subtraction and multiplication using menu editor.

For m :

32
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Code :

Dim a(3, 3), b(3, 3), c(3, 3), i, j, k, sum As Integer

Private Sub ankur()


x = MsgBox("Insert the elements of first Matrix", vbOKOnly, "Message")
For i = 0 To 2
For j = 0 To 2
a(i, j) = Val(InputBox("Enter any number"))
Next j
Next i
x = MsgBox("Insert the elements of second Matrix", vbOKOnly, "Message")
For i = 0 To 2
For j = 0 To 2
b(i, j) = Val(InputBox("Enter any number"))
Next j
Next i
End Sub

Private Sub add_Click()


On Error Resume Next
ankur
For i = 0 To 2
For j = 0 To 2
Print a(i, j),
Next j
Print:
33
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Next i
Print::
For i = 0 To 2
For j = 0 To 2
Print b(i, j),
Next j
Print:
Next i
Print::
For i = 0 To 2
For j = 0 To 2
c(i, j) = a(i, j) + b(i, j)
Next j
Next i
For i = 0 To 2
For j = 0 To 2
Print c(i, j),
Next j
Print:
Next i
End Sub

Private Sub mul_Click()


On Error Resume Next
ankur
For i = 0 To 2
For j = 0 To 2
Print a(i, j),
Next j
Print:
Next i
Print::
For i = 0 To 2
For j = 0 To 2
Print b(i, j),
Next j
Print:
Next i
Print::
For i = 0 To 2
For j = 0 To 2
For k = 0 To 2
sum = sum + a(i, k) * b(k, j)
c(i, j) = sum
Next k
sum = 0
Next j
Next i
For i = 0 To 2
For j = 0 To 2
Print c(i, j),
Next j
Print:
Next i
34
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

End Sub

Private Sub sub_Click()


On Error Resume Next
ankur
For i = 0 To 2
For j = 0 To 2
Print a(i, j),
Next j
Print:
Next i
Print::
For i = 0 To 2
For j = 0 To 2
Print b(i, j),
Next j
Print:
Next i
Print::
For i = 0 To 2
For j = 0 To 2
c(i, j) = a(i, j) - b(i, j)
Next j
Next i
For i = 0 To 2
For j = 0 To 2
Print c(i, j),
Next j
Print:
Next i
End Sub

Output :

35
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no17 : WAP to illustrate call by value and call by reference (to swap to
values).

For m :

36
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Code :

Dim a, b, temp As Integer


Private Sub Command1_Click()

a = InputBox("Enter value of a :- ")


b = InputBox("Enter value of b :- ")
' Before Swapping
Text1.Text = a
Text2.Text = b
' After Swapping
temp = a
a=b
b = temp
Text3.Text = a
Text4.Text = b
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub Command3_Click()
End
End Sub

Output :

37
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no18 : Write a program to calculate factorial of a number using user


defined function.
For m :

38
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Code :
Dim x, a As Integer

Private Function fact(a As Integer) As Integer


Dim i, factorial As Integer
factorial = 1
For i = 1 To a
factorial = factorial * i
Next i
fact = factorial
End Function

Private Sub Command1_Click()


Text1.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
a = Val(Text1.Text)
x = fact(a)
MsgBox ("The factorial of entred number is " & x)
End If
End Sub
Output :

Program no19 : Take input of a word and WAP to check whether it is a palindrome
or not.(without using structure fun).
For m :

39
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Code :
Dim a, b As String
Private Sub Command1_Click()
b = StrReverse(a)
If (StrComp(a, b) = 0) Then
MsgBox ("The Entered String is a pallindrome")
Else
MsgBox ("The Entered String is not a pallindrome")
End If
End Sub

Private Sub Command2_Click()


Text1.Text = ""
End Sub

Private Sub Text1_Change()


a = UCase(Text1.Text)
End Sub
Output :

Program no20 : WAP to find smallest among given three numbers using user defined
procedures.

For m :

40
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Code :
Private Sub Command1_Click()
If Text1.Text < Text2.Text And Text1.Text < Text2.Text Then
MsgBox "First no. is Smaller"
Else
If Text2.Text < Text1.Text And Text2.Text < Text3.Text Then
MsgBox "Second No. is Smaller"
Else
If Text3.Text < Text1.Text And Text3.Text < Text2.Text Then
MsgBox "Third No. is Smaller"
End If
End If
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Output :

Program no21 : WAP to generate. Print and find sum of first n elements of
Fibonacci series using recursion.

For m :

41
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Code :

Private Function fibo(n As Integer) As Integer


If n = 0 Then
fibo = 0
Else
If (n <= 2) Then
fibo = 1
Else
fibo = fibo(n - 1) + fibo(n - 2)
End If
End If
End Function
Private Sub Command1_Click()
Dim c, n As Integer
n = CInt(InputBox("Enter the term of series :- "))
a=0
b=1
For n = 0 To n - 1
c = fibo(n)
Text1.Text = Text1.Text & c & vbNewLine
Next
End Sub
Private Sub Form_Load()
End Sub
If Text1.Text < Text2.Text And Text1.Text < Text2.Text Then
MsgBox "First no. is Smaller"
Else
If Text2.Text < Text1.Text And Text2.Text < Text3.Text Then
MsgBox "Second No. is Smaller"
Else
If Text3.Text < Text1.Text And Text3.Text < Text2.Text Then
MsgBox "Third No. is Smaller"
End If
End If
End If
End Sub

Private Sub Command2_Click()


Text1.Text = ""
Text2.Text = ""
42
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Text3.Text = ""
If Text1.Text < Text2.Text And Text1.Text < Text2.Text Then
MsgBox "First no. is Smaller"
Else
If Text2.Text < Text1.Text And Text2.Text < Text3.Text Then
MsgBox "Second No. is Smaller"
Else
If Text3.Text < Text1.Text And Text3.Text < Text2.Text Then
MsgBox "Third No. is Smaller"
End If
End If
End If
End Sub

Private Sub Command2_Click()


Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub

Output :

Program no22 : WAP to perform read write operations in a sequential file.


For m :

43
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Code :
Option Explicit
Dim s1 As String, s2 As String
Private Sub Command1_Click()
Open "R.txt" For Output As #1
Write #1, Text1, Text2
Close #1
MsgBox "Writing to a file success"
End Sub
Private Sub Command2_Click()
Open "R.txt" For Input As #1
Input #1, s1, s2
Text3.Text = s1
Text4.Text = s2
Close #1
MsgBox "Reading From a File "
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Output :

Program no23:-
Create a user defined-data type having fields name (as string of length 20 bytes). Roll no.
(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.
Write new record (b) Read / display existing record (c) Delete any record
(d) search my record (f) list selected records (e) close the file

44
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no24 : WAP to display records of a table using DAO & bound control code
for buttons to move at first recor, next record, previous record, last record in the table.
For m :

45
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Code :
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim a As String
Dim m, p, c, e, h, b As Integer
Dim per As Double
Private Sub Ankur()
per = (m + p + c + e + h) / 5
Text6.Text = per
If per >= 90 Then Text7.Text = "A+"
If per < 90 And per >= 75 Then Text7.Text = "A"
If per < 75 And per >= 60 Then Text7.Text = "B"
If per < 60 And per >= 45 Then Text7.Text = "C"
If per < 45 Then Text7.Text = "F"
If m > 35 And p > 35 And c > 35 And e > 35 And h > 35 Then
Text8.Text = "Pass"
Else
Text8.Text = "fail"
Text7.Text = "Nil"
End If
End Sub
Private Sub add_Click()
On Error Resume Next
Text9.Text = ""
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
rs.AddNew
rs.edit
46
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

rs(1) = Text9.Text
rs(2) = Text1.Text
rs(3) = Text2.Text
rs(4) = Text3.Text
rs(5) = Text4.Text
rs(6) = Text5.Text
End Sub
Private Sub edit_Click()
rs(1) = Text9.Text
rs(2) = Text1.Text
rs(3) = Text2.Text
rs(4) = Text3.Text
rs(5) = Text4.Text
rs(6) = Text5.Text
rs.Update
End Sub
Private Sub Form_Load()
DBEngine.DefaultType = dbUseODBC
Set db = OpenDatabase("Odbc;dsn=Result")
Set rs = db.OpenRecordset("select * from Table1", dbOpenDynamic, dbExecDirect,
dbOptimistic)
MsgBox "Connected"
Ankit
End Sub
Private Sub Ankit()
Text9.Text = rs(1)
Text1.Text = rs(2)
Text2.Text = rs(3)
Text3.Text = rs(4)
Text4.Text = rs(5)
Text5.Text = rs(6)
End Sub
Private Sub gf_Click()
rs.MoveFirst
Ankit
End Sub
Private Sub gl_Click()
rs.MoveLast
Ankit
End Sub

Private Sub save_Click()


On Error Resume Next
rs.Update
End Sub
Private Sub Text1_Change()
On Error Resume Next
a = Text1.Text
b = Val(Text1.Text)
If a < 48 And a > 57 Then
MsgBox ("Invalid Entry,Insert only numbers")
47
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Text1.Text = ""
ElseIf b > 100 Then
MsgBox ("Invalid Input")
Text1.Text = ""
End If
m = Val(a)
Ankur
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Text2.SetFocus
End Sub
Private Sub Text2_Change()
On Error Resume Next
a = Text2.Text
b = Val(Text2.Text)
If a < 48 And a > 57 Then
MsgBox ("Invalid Entry,Insert only numbers")
Text2.Text = ""
ElseIf b > 100 Then
MsgBox ("Invalid Input")
Text2.Text = ""
End If
p = Val(a)
Ankur
End Sub
Private Sub Text2_GotFocus()
If Text1.Text = "" Then Text1.SetFocus
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Text3.SetFocus
End Sub
Private Sub Text3_Change()
On Error Resume Next
a = Text3.Text
b = Val(Text3.Text)
If a < 48 And a > 57 Then
MsgBox ("Invalid Entry,Insert only numbers")
Text3.Text = ""
ElseIf b > 100 Then
MsgBox ("Invalid Input")
Text3.Text = ""
End If
c = Val(a)
Ankur
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Text4.SetFocus
End Sub

48
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Private Sub Text4_Change()


On Error Resume Next
a = Text4.Text
b = Val(Text4.Text)
If a < 48 And a > 57 Then
MsgBox ("Invalid Entry,Insert only numbers")
Text4.Text = ""
ElseIf b > 100 Then
MsgBox ("Invalid Input")
Text4.Text = ""
End If
e = Val(a)
Ankur
End Sub
Private Sub Text4_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then Text5.SetFocus
End Sub
Private Sub Text5_Change()
On Error Resume Next
a = Text5.Text
b = Val(Text5.Text)
If a < 48 And a > 57 Then
MsgBox ("Invalid Entry,Insert only numbers")
Text5.Text = ""
ElseIf b > 100 Then
MsgBox ("Invalid Input")
Text5.Text = ""
End If
h = Val(a)
Ankur
End Sub

Private Sub Timer1_Timer()


StatusBar1.Panels(1).Text = Time
End Sub
Private Sub Command1_Click()
On Error GoTo l1
rs.MoveNext
Ankit
l1:
If Err.Number = 3021 Then
rs.MoveLast
Ankit
MsgBox "Last Record"
End If
End Sub
Private Sub Command2_Click()
On Error GoTo l1
rs.MovePrevious
Ankit
l1:
If Err.Number = 3021 Then

49
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

rs.MoveFirst
Ankit
MsgBox "First Record"
End If
End Sub

Output :

Program no25 : Create a table using visual data manger and write a program using
RDO & advance bound control to add, delete, edit & navigate records.

VISUAL DATA MANAGER

‘Step 1:

Click on Add Ins Menu ->


Choose Visual Data Manager ->
The VisData Window will be appeared.

50
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Step 2:

In the File Menu ->


Choose New Option then Choose Ms Access Option Version 2.0/7.0 MDB
A save dialog box will appear, prompt the database name and click ok button.

Step 3:

Now In the Database window right click on the Properties command.->


Choose Command New Table

Step 4:
Choose Add Field following dialog will be appeared
Add the required fields.

51
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Step 5:
Close the Add Field and Click on the Build The Table command of Table Structure
Window.

Step 6:
Now add data by double clicking on the table name (recordsofstudent) which is created.

Step 7:
Data base is ready Close the Visual Data Manager.

RDO (Remote Data Access)

To create RDO first we need to create an DSN i.e. Data Source Name.

CREATING DSN (Data Source Name)

Steps:-> Click Start Button and Open Control Panel


-> Select Administrative Tools
-> Open Data Sources (ODBC) Icon following dialog will be appeared

->Select MS Access Data Base and Click Add command next dialog will be appeared

52
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Select Driver do Microsoft Access (*.mdb) option and click Finish Command.
ODBC Microsoft Access Setup Dialog box will be displayed.

-> Enter Data Source Name and Select Database by clicking Select Button.
Click Ok button to create Data Source Name.

CODING FOR RDO


Steps Before
Go to Project Menu
Click on Component command
In the component dialog box select control tab if not selected
1. Check the Microsoft Remote Data Control 6.0
2. Drag the RDO Control on the form.
3. Right Click on the and select property
4. In the property dialog box select
Data Source = dns_record (Data Source Name)
SQL = select * from studentrecord

‘Coding for Advance Bound Control RDO


Private Sub cmd_add_Click()
MSRDC1.Resultset.AddNew
End Sub
53
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Private Sub cmd_del_Click()


MSRDC1.Resultset.Delete
MSRDC1.Resultset.MoveNext
End Sub
Private Sub cmd_edit_Click()
MSRDC1.Resultset.edit
End Sub
Private Sub Update_Click()
MSRDC1.Resultset.Update
End Sub

Program no26 : WAP to access a database using ADO & display a key column in
the combo box list box when an item is selected in it, its corresponding records is shown
in MSH flex grid.

For m :

Code :

Dim con As ADODB.Connection


Dim rs As ADODB.Recordset
Private Sub dis()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text8.Enabled = False
Text9.Enabled = False
End Sub

Private Sub enb()


Text1.Enabled = True
Text2.Enabled = True
54
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text8.Enabled = True
Text9.Enabled = True
End Sub

Private Sub Command1_Click()


Set DataReport1.DataSource = rs
DataReport1.Show
End Sub

Private Sub Command10_Click()


enb
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text8.Text = ""
Text9.Text = ""
Text1.SetFocus
End Sub

Private Sub Command3_Click()


If rs.RecordCount < 0 Then
MsgBox "No Records to delete"
Else
rs.Delete
End If

If rs.EOF = True Then


rs.MovePrevious
Else
rs.MoveNext
End If
Text1.Text = rs!Name
Text2.Text = rs!maths
Text3.Text = rs!eng
Text4.Text = rs!science
Text8.Text = rs!hindi
Text9.Text = rs!sst
rs.Update
End Sub

Private Sub Command4_Click()


Unload Me
End Sub

Private Sub Command5_Click()


dis
If rs.RecordCount < 0 Then
MsgBox "No records Found"
Else
55
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

rs.MoveFirst
End If
End Sub

Private Sub Command6_Click()


dis
If rs.BOF = True Then
MsgBox "Begning Of File"
Else
rs.MovePrevious
Text1.Text = rs!Name
Text2.Text = rs!maths
Text3.Text = rs!eng
Text4.Text = rs!science
Text8.Text = rs!hindi
Text9.Text = rs!sst
End If
End Sub

Private Sub Command7_Click()


dis
If rs.EOF = True Then
MsgBox "End Of File"
Else
rs.MoveNext
Text1.Text = rs!Name
Text2.Text = rs!maths
Text3.Text = rs!eng
Text4.Text = rs!science
Text8.Text = rs!hindi
Text9.Text = rs!sst
End If
End Sub

Private Sub Command8_Click()


dis
If rs.RecordCount < 0 Then
MsgBox "No records Found"
Else
rs.MoveLast
End If
End Sub

Private Sub Command9_Click()


rs.AddNew
rs!Name = Text1.Text
rs!maths = Text2.Text
rs!eng = Text3.Text
rs!science = Text4.Text
rs!hindi = Text8.Text
rs!sst = Text9.Text
rs.Update
End Sub

56
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Private Sub Form_Load()


dis
Set con = New ADODB.Connection
con.Provider = "Microsoft.Jet.OLEDB.3.51"
con.Open "e:\project vb\project vb.mdb"
Set rs = New ADODB.Recordsetrs.Open "table1", con, adOpenDynamic,
adLockOptimistic, adCmdTable
MSFlexGrid1.FormatString = "^Flex|^Student Name|^Roll No.|^Maths|^English|
^Science|^Hindi|^Social Science"
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then
Text2.SetFocus
End If
Text1.FontSize = 13
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then
Text3.SetFocus
End If
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then
Text4.SetFocus
End If
End Sub

Private Sub Text4_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then
Text5.SetFocus
End If
End Sub

Private Sub Text5_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then
Text8.SetFocus
End If
End Sub

Private Sub Text8_KeyPress(KeyAscii As Integer)


If KeyAscii = 13 Then
Text9.SetFocus
End If
End Sub

Private Sub Text9_KeyPress(KeyAscii As Integer)


MSFlexGrid1.AllowUserResizing = flexResizeBoth
If KeyAscii = 13 Then
MSFlexGrid1.Text = Text1.Text
MSFlexGrid1.Col = MSFlexGrid1.Col + 1
MSFlexGrid1.Text = Text2.Text
57
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

MSFlexGrid1.Col = MSFlexGrid1.Col + 1
MSFlexGrid1.Text = Text3.Text
MSFlexGrid1.Col = MSFlexGrid1.Col + 1
MSFlexGrid1.Text = Text4.Text
MSFlexGrid1.Col = MSFlexGrid1.Col + 1
MSFlexGrid1.Text = Text5.Text
MSFlexGrid1.Col = MSFlexGrid1.Col + 1
MSFlexGrid1.Text = Text8.Text
MSFlexGrid1.Col = MSFlexGrid1.Col + 1
MSFlexGrid1.Text = Text9.Text
End If
End Sub

Output :

Program no27 : Using data Environment create a program to display records of any
table.

Steps to Create Data Environment

1.In the New Project select Data Project


58
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

2.By selecting this option a form, a Data environment and a data report is loaded
automatically.

3.Now Open the Data Environment Window


4.Right Click on the Connection1 choose property option
5. Select Microsoft Jet 4.0 OLE DB Provider
6. Go to Connection Tab

7.Select Database and test connection then


Click OK Button.
8.Again Right Click on the Connection and
Choose Add Command Button.
9.Now right click on the command property
and open property.
10.Choose Database Object type Table and
Object what you have created (Table Name).
11.Now Drag and Drop the fields on the
form then start conding.

59
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Code :

Private Sub cmd_first_Click()


DataEnvironment1.rsCommand1.MoveFirst
End Sub

Private Sub cmd_last_Click()


DataEnvironment1.rsCommand1.MoveLast
End Sub

Private Sub cmd_next_Click()


DataEnvironment1.rsCommand1.MoveNext
If DataEnvironment1.rsCommand1.EOF Then
DataEnvironment1.rsCommand1.MoveLast
MsgBox ("Last Record")
End If
End Sub

Private Sub cmd_Prev_Click()


DataEnvironment1.rsCommand1.MovePrevious
If DataEnvironment1.rsCommand1.BOF Then
DataEnvironment1.rsCommand1.MoveFirst
MsgBox ("First Record")
End If
End Sub

60
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Private Sub Command1_Click()


DataReport1.Show
End Sub

Program no28:-
WAP to generate mark sheet of students in a class through data report.

61
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no29:-WAP to illustrate various key board and mouse events.


Code—
Form MouseUp And MouseDown in Form1.frm
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As
Single)
Circle (X, Y), 75
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As
Single)
Circle (X, Y), 75
End Sub
For MouseMove Event in Form2.frm
62
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As


Single)
Circle (X, Y), 75
End Sub
For KeyPress Event form3.frm
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < "65" Or KeyAscii > "91" Then
If KeyAscii < "97" Or KeyAscii > "122" Then
KeyAscii = 0 'set character to Null if Not
MsgBox "Enter Only Character"
End If
End If
End Sub
For KeyUp/Key Down Events
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyF2 Then
MsgBox "You have pressed the F2 Key"
End If
End Sub

Outputs:-Mouse Move Event

Mouseup / Mouse Down Events:

KeyUp / KeyDown Event:-

KeyPress Event:-
63
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Program no30:-
Using drive, directive and file list box ( it will shown only .bmp files ). Let the user select
the bmb files, which will appear in picture box as user click on any item in list box.

Form View:-

Run Time Source Code:-


Private Sub Dir1_Change()
File1.Pattern = Text1.Text
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()


Dir1.Path = Drive1.Drive
End Sub

Private Sub File1_Click()


Picture1.Picture = LoadPicture(File1.Path & File1.List(File1.ListIndex))
End Sub

Private Sub Text1_Change()


Dir1_Change
End SubOutput View:-

64
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Ass-:-31--

Using toolbar design an interface for string manipulation. Toolbar should have tabs to
Find length of string
No of blank spaces in string
Reverse the string
Also show current date & time in status bar.

Code:-
Dim I As Integer
Dim SUM As Integer
Dim btn As Button
Private Sub Command1_Click()
Text2.Text = Len(Text1.Text)
End Sub
Private Sub Command2_Click()
Text3.Text = StrReverse(Text1.Text)
End Sub
Private Sub Command3_Click()
SUM = 0
For I = 0 To (Len(Text1.Text)) Step 1
If InStr(1, Text1.Text, " ") = 1 Then
SUM = SUM + 1
End If
Next I
Text4.Text = SUM
End Sub
Private Sub Form_Load()
Dim btn As Button
Set btn = Toolbar1.Buttons.Add(1, , "Length", tbrDefault)
Set btn = Toolbar1.Buttons.Add(2, , "Reverse", tbrDefault)
Set btn = Toolbar1.Buttons.Add(3, , "Blank Space", tbrDefault)
65
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

Dim pn As Panel
Set pn = StatusBar1.Panels.Add()
pn.MinWidth = 1
Set pn = StatusBar1.Panels.Add(, , , sbrDate)
Set pn = StatusBar1.Panels.Add(, , , sbrTime)
pn.Bevel = sbrInset
pn.Alignment = sbrRight
StatusBar1.Panels(1).AutoSize = sbrContents
StatusBar1.Panels(1).Text = "Date and Time"
End Sub
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
If Button.Index = 1 Then
Command1_Click
Else
If Button.Index = 2 Then
Command2_Click
Else
If Button.Index = 3 Then

Command3_Click
End If
End If
End If
End Sub
Output View:-

66
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg

67
Lab Manual: CS-(Visual Basic)

You might also like