Program No-01 Aim: WAP To Perform Arithmetic Operation Using Command Button. Code
Program No-01 Aim: WAP To Perform Arithmetic Operation Using Command Button. Code
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
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
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
m = Val(a)
Ankur
End Sub
7
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg
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
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
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
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
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
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 :
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 :
End Sub
17
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg
Output :
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 :
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
23
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg
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 :
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 :
HScroll3.Value = 0
HScroll4.Value = 0
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 :
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 :
For I = 0 To R - 1
B(I) = Val(InputBox("Enter The Integers"))
Next I
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 :
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
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 :
Output :
37
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg
38
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg
Code :
Dim x, a As Integer
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
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 :
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
Output :
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
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
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.
‘Step 1:
50
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg
Step 2:
Step 3:
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.
To create RDO first we need to create an DSN i.e. Data Source Name.
->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.
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 :
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text8.Enabled = True
Text9.Enabled = True
End Sub
rs.MoveFirst
End If
End Sub
56
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.
2.By selecting this option a form, a Data environment and a data report is loaded
automatically.
59
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg
Code :
60
Lab Manual: CS-(Visual Basic)
Department of Computer Science
Rungta College of Science & Technology, Durg
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
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:-
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)