Master of Computer Application
1st Semester
Session 2024-2026
Visual Basic & Database Systems
(20BCC11CL1 based on paper 20BCC11C3)
Submitted To: Mr. Aadi Submitted by: KUSHAL
(Assistant Professor) Student ID: 145793
Certificate
This is to certify that KUSHAL S/O Mr. Rajesh kumar has submitted
a practical file for fulfilment of MCA 1 st semester lab course for Visual Basic &
Database Systems.
Submitted To: Mr. Aadi Submitted by: KUSHAL
(Assistant Professor) Student ID: 145793
INDEX
S.No. Programs Date Remarks
1 Write a program to perform arithmetic operation using command buttons (declare
variable globally).
2 Write a program to find. Area of circle.
3 Write a program to take input of principal, rate and time and calculate simple interest
and compound interest.
4 Write a program to design an interface, which will appear like mark sheet. It will take
input of marks in five subjects and calculate total marks and percentage then provide
grade according to following criteria. (Using nested if) (Use tab index property to move
focus).
If % Then Grade
> = 90 A+
> = 75 & < 90 A
> = 60 & < 75 B
> = 45 & < 60 C
Otherwise F
5 Write a program to print no 1 to 20.
6 Write a program to check whether an entered no. is prime or not. (Using for loop &
while).
7 WAP to search an element for a one dimension static array.
8 WAP to sort a dynamic array of n umbers
9 WAP to take input of two matrices and perform their addition
10 WAP to use methods used in collection
11 WAP to illustrate call by value and call by reference (to swap to values)
12 WAP to find smallest among given three numbers using user defined procedures.
13 WAP to display picture and image control.
Practical 1
Aim: Write a program to perform arithmetic operation using command buttons (declare
variable globally).
flublic Class Form1
Dim num1, num2 As Integer
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
num1 = Val(TextBox1.Text)
num2 = Val(TextBox2.Text)
TextBox3.Text = num1 + num2
End Sub
flrivate Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
num1 = Val(TextBox1.Text)
num2 = Val(TextBox2.Text)
TextBox3.Text = num1 - num2
End Sub
flrivate Sub Button3_Click(sender As Object, e As EventArgs) Handles
Button3.Click
num1 = Val(TextBox1.Text)
num2 = Val(TextBox2.Text)
TextBox3.Text = num1 * num2
End Sub
flrivate Sub Button4_Click(sender As Object, e As EventArgs) Handles
Button4.Click
num1 = Val(TextBox1.Text)
num2 = Val(TextBox2.Text)
TextBox3.Text = num1 / num2
End Sub
End Class
Output:
Practical 2
Aim: Write a program to find. Area of circle.
flublic Class question2
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim r As Integer
r = Val(radiusTxt.Text)
outputTxt.Text = 22 / 7 * r * r
End Sub
End Class
Output:
Practical 3
Aim: Write a program to take input of principal, rate and time and calculate simple
interest and compound interest.
flublic Class question3
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim principle As Integer
Dim rate, time As Double
Dim simpleIntrest, compoundIntrest As Double
principle = Val(pTxt.Text)
rate = Val(rTxt.Text)
time = Val(tTxt.Text)
siTxt.Text = principle * rate * time
ciTxt.Text = principle * (1 + rate) ^ time - principle
End Sub
End Class
Output:
Practical 4
Aim: Write a program to design an interface, which will appear like mark sheet. It will
take input of marks in five subjects and calculate total marks and percentage then
provide grade according to following criteria. (Using nested if) (Use tab index property to
move focus).
If % Then Grade
> = 90 A+
> = 75 & < 90 A
> = 60 & < 75 B
> = 45 & < 60 C
Otherwise F
flublic Class question4
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim hMarks, eMarks, mMarks, sMarks, sSmarks As Double
Dim totalMarks, percentage As Double
Dim grade As String
hMarks = Val(hTxt.Text)
eMarks = Val(eTxt.Text)
mMarks = Val(mTxt.Text)
sMarks = Val(sTxt.Text)
sSmarks = Val(sSTxt.Text)
totalMarks = hMarks + eMarks + mMarks + sMarks + sSmarks
percentage = totalMarks / 5
If percentage >= 45 Then
If percentage >= 60 Then
If percentage >= 75 Then
If percentage >= 90 Then
grade = "A+"
Else
grade = "A"
End If
Else
grade = "B"
End If
Else
grade = "C"
End If
Else
grade = "F"
End If
gradeTxt.Text = grade
End Sub
End Class
Output:
Practical 5
Aim: Write a program to print no 1 to 20.
flublic Class question5
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim counter As Integer
For counter = 1 To 1000 Step 10
counter += 1
flrint(counter)
ext
End Sub
End Class
Output:
Practical 6
Aim: Write a program to check whether an entered no. is prime or not. (Using for loop &
while).
flublic Class question6
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim num As Integer
Dim isflrime As Boolean = True
num = Val(TextBox1.Text)
For counter As Integer = 2 To Math.Sqrt(num)
If num Mod counter = 0 Then
isflrime = False
Exit For
End If
ext
If isflrime Then
MsgBox(num fi " is a prime number")
Else
MsgBox(num fi " is not a prime number")
End If
End Sub
End Class
Output:
Practical 7
Aim: Write a program to search an element in array.
Imports System.Windows.Forms.VisualStyles.VisualStyleElement
flublic Class question7
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim numbers() As Integer = {5, 10, 15, 20, 25, 30} Dim
searchElement As Integer = Val(TextBox1.Text) Dim
found As Boolean = False
For i As Integer = 0 To numbers.Length - 1
If numbers(i) = searchElement Then
found = True
Exit For
End If
ext
If found Then
MsgBox(searchElement fi " is found in the array.")
Else
MsgBox(searchElement fi " is not found in the array.")
End If
End Sub
End Class
Output:
Here we are finding the element in predefined array inside the code and not in dynamic array.
17
Practical 8
Aim: Write a program to sort a dynamic array of n numbers
flublic Class question8
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim input As String = TextBox1.Text
Dim str umbers() As String = input.Split(" ")
Dim numbers(str umbers.Length - 1) As Integer
For i As Integer = 0 To str umbers.Length - 1
If Integer.Tryflarse(str umbers(i), numbers(i)) = False Then
MsgBox("Invalid input. fllease enter valid numbers.")
Exit Sub
End If
ext
BubbleSort(numbers)
Dim sortedArray As String = String.Join(" ", numbers)
MsgBox("Sorted Array: " fi sortedArray)
End Sub
flrivate Sub BubbleSort(ByRef arr() As Integer)
Dim n As Integer = arr.Length
Dim temp As Integer
For i As Integer = 0 To n - 2
For j As Integer = 0 To n - i - 2
If arr(j) > arr(j + 1) Then
temp = arr(j)
arr(j) = arr(j + 1)
arr(j + 1) = temp
End If
ext
ext
End Sub
End Class
Output:
Practical 9
Aim: Write a program to take input of two matrices and perform their addition
flublic Class question9
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim numRows As Integer = Val(TextBox1.Text)
Dim numCols As Integer = Val(TextBox2.Text) If
numRows <= 0 Or numCols <= 0 Then
MsgBox("Invalid matrix dimensions. fllease enter positive values.")
Exit Sub
End If
Dim matrix1(numRows - 1, numCols - 1) As Integer
Dim matrix2(numRows - 1, numCols - 1) As Integer
Dim resultMatrix(numRows - 1, numCols - 1) As Integer
For i As Integer = 0 To numRows - 1
For j As Integer = 0 To numCols - 1
Dim input1 As String = InputBox("Enter element at row " fi (i + 1) fi
", column " fi (j + 1) fi " of Matrix 1:")
If Integer.Tryflarse(input1, matrix1(i, j)) = False Then
MsgBox("Invalid input. fllease enter valid numbers.")
Exit Sub
End If
ext
ext
For i As Integer = 0 To numRows - 1
For j As Integer = 0 To numCols - 1
Dim input2 As String = InputBox("Enter element at row " fi (i + 1) fi ",
column " fi (j + 1) fi " of Matrix 2:")
If Integer.Tryflarse(input2, matrix2(i, j)) = False Then
MsgBox("Invalid input. fllease enter valid numbers.")
Exit Sub
End If
ext
ext
' flerform matrix addition
For i As Integer = 0 To numRows - 1
For j As Integer = 0 To numCols - 1
resultMatrix(i, j) = matrix1(i, j) + matrix2(i, j)
ext
ext
Dim resultString As String = "Result Matrix:" fi vbCrLf
For i As Integer = 0 To numRows - 1
For j As Integer = 0 To numCols - 1
resultString fi= resultMatrix(i, j) fi " "
ext
resultString fi= vbCrLf
ext
MsgBox(resultString)
End Sub
End Class
Output:
Entering the size of Matrix
Entering values of matrix 1
Entering values of matrix 2
The resulted addition matrix will be
Practical 10
Aim: Write a program to use methods used in collection.
flublic Class question10
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim myList As ew List(Of Integer)
' Adding items to the list
myList.Add(10)
myList.Add(20)
myList.AddRange({30, 40, 50})
myList.Insert(1, 15)
' Removing items from the list
myList.Remove(40)
myList.RemoveAt(3)
'myList.Clear() this command will empty the list thats why not xecuting this
' Accessing items in the list
txtOutput.Text = "List Contents:" fi vbCrLf
For Each item As Integer In myList
txtOutput.Text fi= item.ToString() fi " " fi vbCrLf
ext
End Sub
End Class
Output:
Here we are performing some operations on a collection which is predefined in the program and is not
dynamic.
24
Practical 11
Aim: Write a program to illustrate call by value and call by reference (to swap to values)
flublic Class question11
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim num1 As Integer = Val(num1Txt.Text)
Dim num2 As Integer = Val(num2Txt.Text)
' Swap values using call by value
SwapByValue(num1, num2)
TextBox1.Text = "Call by Value: " fi " um1 = " fi num1 fi ", um2 = " fi num2
' Swap values using call by reference
SwapByReference(num1, num2)
TextBox2.Text = "Call by Reference: " fi " um1 = " fi num1 fi ", um2 = " fi
num2
End Sub
flrivate Sub SwapByValue(ByVal a As Integer, ByVal b As Integer)
Dim temp As Integer = a
a = b
b = temp
End Sub
flrivate Sub SwapByReference(ByRef a As Integer, ByRef b As Integer)
Dim temp As Integer = a
a = b
b = temp
End Sub
End Class
Output:
Practical 12
Aim: Write a program to find smallest among given three numbers using user defined
procedures.
flublic Class question12
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim num1 As Integer = Val(TextBox1.Text)
Dim num2 As Integer = Val(TextBox2.Text)
Dim num3 As Integer = Val(TextBox3.Text)
Dim smallest As Integer = FindSmallest(num1, num2, num3)
TextBox4.Text = "The smallest number is: " fi smallest
End Sub
flrivate Function FindSmallest(ByVal a As Integer, ByVal b As Integer, ByVal c As
Integer) As Integer
Dim smallest As Integer = a
If b < smallest Then
smallest = b
End If
If c < smallest Then
smallest = c
End If
Return smallest
End Function
End Class
Output:
Practical 13
Aim: Write a program to display picture and image control.
flublic Class question13
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
' Create and configure the OpenFileDialog
Dim openFileDialog1 As ew OpenFileDialog()
openFileDialog1.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.gif;*.bmp|All
Files|*.*"
openFileDialog1.Title = "Select an Image File"
' Show the OpenFileDialog
If openFileDialog1.ShowDialog() = DialogResult.OK Then
Try
' Load the selected image into the flictureBox
flictureBox1.Image = Image.FromFile(openFileDialog1.File ame)
Catch ex As Exception
MessageBox.Show("Error loading the image: " fi ex.Message)
End Try
End If
End Sub
End Class
29
Output:
Selecting the image from dialog box
30
Showing the Image
flublic Class question13
flrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
' Get the image path from the TextBox
Dim imageflath As String =
"C:\Users\Admin\OneDrive\flictures\Screenshots\randomimage.png"
' Check if the path is not empty
If ot String.Is ullOrEmpty(imageflath) Then
Try
' Display the image in the flictureBox
flictureBox1.Image = Image.FromFile(imageflath)
Catch ex As Exception
MessageBox.Show("Error loading the image: " fi ex.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Else
MessageBox.Show("fllease enter a valid image path.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
End Class
Output: