VB Practical
VB Practical
Governme
nt PG
Collage
Practical Sector 9
Gurgaon
File
Visual Basic
Subject Code - BCA 304
Submitted Submitted
To By
Mrs. Sheela Mithlesh
Mam Kumar
Signature BCA 5th Sem
Sec-B
………………
Roll No. – 64
…………
Session 2024-25
1
Visual Basic Practical – BCA 5th Sem
Index
S.No. Content Page No. Date
2
Visual Basic Practical – BCA 5th Sem
Practical – 1
1. WAP to perform arithmetic operation using command buttons. (Declare variables
globally).
Public Class Form1
num1 = CDbl(txtNum1.Text)
num2 = CDbl(txtNum2.Text)
End Sub
num1 = CDbl(txtNum1.Text)
num2 = CDbl(txtNum2.Text)
End Sub
num1 = CDbl(txtNum1.Text)
num2 = CDbl(txtNum2.Text)
3
Visual Basic Practical – BCA 5th Sem
End Sub
num1 = CDbl(txtNum1.Text)
num2 = CDbl(txtNum2.Text)
Else
End If
End Sub
End Class
Sample Output:
4
Visual Basic Practical – BCA 5th Sem
Practical – 2
2. Design an interface, which will appear like marksheet. 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
Public Class MarksheetForm
marks(0) = Convert.ToDouble(txtSubject1.Text)
marks(1) = Convert.ToDouble(txtSubject2.Text)
marks(2) = Convert.ToDouble(txtSubject3.Text)
marks(3) = Convert.ToDouble(txtSubject4.Text)
marks(4) = Convert.ToDouble(txtSubject5.Text)
totalMarks = 0
For i As Integer = 0 To 4
totalMarks += marks(i)
Next
5
Visual Basic Practical – BCA 5th Sem
grade = "A+"
grade = "A"
grade = "B"
grade = "C"
Else
grade = "F"
End If
End Sub
End Class
Sample Output:
Input:
o txtSubject1 = 85
o txtSubject2 = 78
o txtSubject3 = 90
o txtSubject4 = 82
o txtSubject5 = 88
After clicking the Calculate button:
o Total Marks: 423
o Percentage: 84.60%
o Grade: A
6
Visual Basic Practical – BCA 5th Sem
Practical – 3
3. WAP to create a simple calculator (Using control array)
Public Class Form1
End Sub
num1 = Convert.ToDouble(txtDisplay.Text)
operation = button.Text
txtDisplay.Clear()
End Sub
num2 = Convert.ToDouble(txtDisplay.Text)
Case "+"
Case "-"
Case "*"
7
Visual Basic Practical – BCA 5th Sem
Case "/"
Else
txtDisplay.Text = "Error"
Exit Sub
End If
End Select
txtDisplay.Text = result.ToString()
End Sub
txtDisplay.Clear()
num1 = 0
num2 = 0
operation = ""
End Sub
Dim buttonTexts() As String = {"7", "8", "9", "/", "4", "5", "6", "*", "1", "2", "3", "-", "0", ".", "=",
"+"}
btn.Text = buttonTexts(i)
8
Visual Basic Practical – BCA 5th Sem
btn.Width = btnWidth
btn.Height = btnHeight
btn.Left = xPos
btn.Top = yPos
' Assign click events to operation buttons and the equals button
If btn.Text = "+" OrElse btn.Text = "-" OrElse btn.Text = "*" OrElse btn.Text = "/" Then
End If
Me.Controls.Add(btn)
xPos += btnWidth + 5
If (i + 1) Mod 4 = 0 Then
xPos = 10
yPos += btnHeight + 5
End If
Next
End Sub
CreateButtonArray()
End Sub
End Class
9
Visual Basic Practical – BCA 5th Sem
Practical – 4
4. Write a program to check whether a centered no. is prime or not. (Using for loop &
Exit for).
Public Class PrimeCheckForm
isPrime = False
Else
' Check for factors from 2 to the square root of the number
isPrime = False
End If
Next
End If
If isPrime Then
Else
lblResult.Text = "The number " & num.ToString() & " is not prime."
End If
End Sub
End Class
10
Visual Basic Practical – BCA 5th Sem
Sample Output:
Input: 7
Output: The number 7 is prime.
Input: 12
Output: The number 12 is not prime.
11
Visual Basic Practical – BCA 5th Sem
Practical – 5
5. Write a program which will count all vowels, consonants, digits, special characters
and blank spaces in a sentences (Using select case)
Public Class CharacterCounterForm
Select Case ch
Case "A"c, "E"c, "I"c, "O"c, "U"c, "a"c, "e"c, "i"c, "o"c, "u"c
vowelCount += 1
consonantCount += 1
digitCount += 1
spaceCount += 1
Case Else
specialCharCount += 1
End Select
Next
12
Visual Basic Practical – BCA 5th Sem
End Sub
End Class
Sample Output:
13
Visual Basic Practical – BCA 5th Sem
Practical – 6
6. WAP to illustrate all functionalities of listbox and combobox.
cmbBox.Items.Add("Apple")
cmbBox.Items.Add("Banana")
cmbBox.Items.Add("Orange")
cmbBox.Items.Add("Grapes")
lstBox.Items.Add("Red")
lstBox.Items.Add("Green")
lstBox.Items.Add("Blue")
lstBox.Items.Add("Yellow")
End Sub
lstBox.Items.Add(txtItem.Text)
txtItem.Clear()
End If
End Sub
14
Visual Basic Practical – BCA 5th Sem
lstBox.Items.Remove(lstBox.SelectedItem)
Else
End If
End Sub
End If
End Sub
cmbBox.Items.Add(txtItem.Text)
txtItem.Clear()
End If
End Sub
cmbBox.Items.Remove(cmbBox.SelectedItem)
Else
End If
End Sub
15
Visual Basic Practical – BCA 5th Sem
End Sub
End Class
Sample Output:
Initial State:
o ListBox contains: Red, Green, Blue, Yellow.
o ComboBox contains: Apple, Banana, Orange, Grapes.
Interaction:
o Add a new item ("Purple") to ListBox or ComboBox by typing in txtItem and
clicking the appropriate Add button.
o Select an item in ListBox or ComboBox to display it in the respective label.
o Click the Remove button to remove the selected item from the ListBox or
ComboBox.
16
Visual Basic Practical – BCA 5th Sem
Practical – 7
7. WAP using check boxes for following font effects.
Bold
Italic
Underline
Font color
ApplyFontStyle()
End Sub
ApplyFontStyle()
End Sub
If currentFontSize > 2.0F Then ' Ensure font size doesn't go below 2
ApplyFontStyle()
End If
End Sub
17
Visual Basic Practical – BCA 5th Sem
lblSampleText.ForeColor = colorDialog.Color
End If
End Sub
If chkBold.Checked Then
End If
If chkItalic.Checked Then
End If
If chkUnderline.Checked Then
End If
' Apply the new font style and size to the label
End Sub
End Class
Sample Output:
18
Visual Basic Practical – BCA 5th Sem
CheckBoxes:
o chkBold labeled "Bold".
o chkItalic labeled "Italic".
o chkUnderline labeled "Underline".
Buttons:
o btnIncreaseFont labeled "Increase Font Size".
o btnDecreaseFont labeled "Decrease Font Size".
o btnFontColor labeled "Change Font Color".
Label:
o lblSampleText to display the text with applied effects.
Form Layout:
o Place checkboxes and buttons conveniently for user interaction.
Position lblSampleText at the top or center for clear visibility of the changes.
19
Visual Basic Practical – BCA 5th Sem
Practical – 8
End Sub
End Sub
picRocket.Top -= rocketSpeed
' Stop the rocket when it reaches the top of the form
tmrRocketLaunch.Enabled = False
End If
End Sub
End Class
20
Visual Basic Practical – BCA 5th Sem
Step-by-Step Setup:
Sample Output:
21
Visual Basic Practical – BCA 5th Sem
Practical – 9
9. WAP to take input of two matrices and perform their addition, subtraction and
multiplication.
Public Class MatrixOperationsForm
rows = CInt(txtRows.Text)
cols = CInt(txtCols.Text)
ClearMatrixInputs()
End Sub
22
Visual Basic Practical – BCA 5th Sem
Next
Next
Next
Next
End Sub
Next
Next
End Sub
Next
Next
End Sub
23
Visual Basic Practical – BCA 5th Sem
resultMatrix(i, j) = 0
Next
Next
Next
Next
Next
End Sub
Next
Next
MessageBox.Show(resultText, operation)
End Sub
txtRows.Clear()
24
Visual Basic Practical – BCA 5th Sem
txtCols.Clear()
End Sub
End Class
Sample Output:
Initial State:
o User inputs dimensions (e.g., 2 rows and 2 columns).
Matrix Input:
o User is prompted to enter values for Matrix A and Matrix B.
Results:
o Upon clicking the operation buttons (Add, Subtract, Multiply), a message box
displays the resulting matrix.
25
Visual Basic Practical – BCA 5th Sem
Practical – 10
10. WAP to generate, print and find sum of first n elements of fibonacci series
using recursion using user defined procedures..
Public Class FibonacciSeriesForm
Dim n As Integer
lblSum.Text = "Sum of first " & n & " Fibonacci numbers: " & sum
Else
End If
End Sub
For i As Integer = 0 To n - 1
fibList.Add(Fibonacci(i))
Next
Return fibList
End Function
26
Visual Basic Practical – BCA 5th Sem
If n <= 1 Then
Return n
Else
End If
End Function
sum += number
Next
Return sum
End Function
End Class
Sample Output:
Fibonacci Series: 0, 1, 1, 2, 3
Sum of first 5 Fibonacci numbers: 7
27