Practical No: 03
Program Code:
Write a program using MessageBox and Arithmetic Expressions –
Module Module1
Dim i, j, r As Integer
Sub Main()
[Link]("Enter First Value=")
i = [Link]()
[Link]("Enter Second Value=")
j = [Link]()
[Link]()
MsgBox("Addition =" & (i + j))
MsgBox("Substraction =" & (i - j))
MsgBox("Multiplication =" & (i * j))
MsgBox("Division =" & (i / j))
End Sub
End Module
Results (Output of the Program)
Enter First Value =
10
Enter Second Value=
5
---------------------------
MessageBoxPractical3
---------------------------
Addition =15
---------------------------
OK
---------------------------
1. Implement the program to generate result of any arithmetic operation using
MessageBox().
Public Class Form1
Dim n As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
n = Val([Link]) + Val([Link])
MsgBox("Addition=" & n)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]
n = Val([Link]) - Val([Link])
MsgBox("Substraction=" & n)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles [Link]
n = Val([Link]) * Val([Link])
MsgBox("Multiplication=" & n)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles [Link]
n = Val([Link]) / Val([Link])
MsgBox("Division=" & n)
End Sub
End Class
-Arithmetic Operation using msgbox
Addition=60
OK
2. Write a program using InputBox(), MessageBox() & perform various Arithmetic
expressions.
Public Class Form1
Dim i, j, r As Integer
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]
i = InputBox("Enter First Value")
j = InputBox("Enter Second Value")
r = Val(i) - Val(j)
MsgBox("Substract = " & r)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles [Link]
i = InputBox("Enter First Value")
j = InputBox("Enter Second Value")
r = Val(i) / Val(j)
MsgBox("Divide = " & r)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles [Link]
i = InputBox("Enter First Value")
j = InputBox("Enter Second Value")
r = Val(i) * Val(j)
MsgBox("Multiply = " & r)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
i = InputBox("Enter First Value")
j = InputBox("Enter Second Value")
r = Val(i) + Val(j)
MsgBox("Addition = " & r)
End Sub
End Class
Output:
Inputbox_Msgbox
Addition = 68
OK
Practical No: 04
. Program Code:
Write a program using if-else statement –
Module Module1
Sub Main()
Dim n As Integer
[Link]("Enter a Number")
n = [Link]()
If (n > 0) Then
[Link]("Number is Positive")
Else
[Link]("Number is Negative")
End If
[Link]()
End Sub
End Module
Results (Output of the Program)
Enter a number:
9
Number is Positive
1. Write program for finding greatest among three numbers –
Module Module1
Sub Main()
Dim a, b, c As Integer
[Link]("Enter the values of a, b and c:")
a = Val([Link]())
b = Val([Link]())
c = Val([Link]())
If (a > b) Then
If (a > c) Then
[Link]("Greatest Number is:" & a)
Else
[Link]("Greatest Number is:" & c)
End If
Else
If (b > c) Then
[Link]("Greatest Number is:" & b)
Else
[Link]("Greatest Number is:" & c)
End If
End If
[Link]()
End Sub
End Module
Results (Output of the Program)
Enter the values of a, b and c:
23 65 12
Greatest Number is : 65
2. Implement the program using if-else statement to find the number is even or odd –
Module Module1
Dim i As Integer
Sub Main()
[Link]("Enter Number")
i = [Link]()
If ((i Mod 2) = 0) Then
[Link]("Number is Even")
Else
[Link]("Number is Odd")
End If
[Link]()
End Sub
End Module
Results (Output of the Program)
Enter a number:
9
Number is Odd
Practical No: 05
X. Program Code :
Write a Program using select case statement in [Link]
Module Module1
Sub Main()
Dim grade As String
[Link]("Enter Your grade")
grade = [Link]()
Select Case grade
Case "A"
[Link]("High Distinction")
Case "A-"
[Link]("Distinction")
Case "B"
[Link]("Credit")
Case "C"
[Link]("Pass")
Case Else
[Link]("Fail")
End Select
[Link]()
End Sub
End Module
Results (Output of the Program)
Enter Your grade
A
High Distinction
1. Implement the program using Select Case statement to count the number of Vowels in
A to Z alphabets.
Module Module1
Sub Main()
Dim str As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim numberOfVowels As Integer = 0
For Each c As Char In str
Select Case c
Case "A"c, "E"c, "I"c, "O"c, "U"c
numberOfVowels = numberOfVowels + 1
End Select
Next
[Link]("Number of vowels: " & numberOfVowels)
[Link]()
End Sub
End Module
Output:
Number of vowels: 5
2. Develop a program for performing arithmetic operations –
Module Module1
Sub Main()
Dim N1, N2, Result, choice As Integer
Do
[Link]("Menu:-\[Link]\[Link]" & _
"\[Link]\[Link]\[Link].")
[Link]("Enter choice: ")
choice = [Link]()
[Link]("Enter number 1: ")
N1 = [Link]()
[Link]("Enter number 2: ")
N2 = [Link]()
Select Case choice
Case 1
Result = N1 + N2
[Link]("Sum = " & Result)
Case 2
Result = N1 - N2
[Link]("Difference = " & Result)
Case 3
Result = N1 * N2
[Link]("Product = " & Result)
Case 4
Result = N1 \ N2
[Link]("Quotient = " & Result)
Result = N1 Mod N2
[Link]("Remainder = " & Result)
Case 5
Exit Sub
Case Else
[Link]("Wrong option ...")
End Select
Loop While choice <> 5
End Sub
End Module
Output:
Menu:-\[Link]\[Link]\[Link]\[Link]\[Link].
Enter choice: 1
Enter number 1: 57
Enter number 2: 87
Sum = 144
Menu:-\[Link]\[Link]\[Link]\[Link]\[Link].
Enter choice: 5
[Type text]
Practical No 06
Program Code :
Write a program using While & Do loop in [Link]
For while loop.
Module Module1
Sub Main()
Dim a As Integer = 1
While (a < 10)
[Link](a)
a = a + 1
End While
[Link]()
End Sub
End Module
Output:
1
2
3
4
5
6
7
8
9
For Do loop.
Module Module1
Sub Main()
Dim a As Integer = 1
Do
[Link](a)
a = a + 1
Loop While (a<10)
[Link]()
End Sub
End Module
Output:
1
2
3
4
5
6
7
8
9
[Type text]
[Type text]
1. Write a program using While statement to print the prime numbers between 1 to 100.
Module Module1
Sub Main()
Dim i, j, c As Integer
c=0
i=2
While (i <= 100)
j=2
While (j < i)
If (i Mod j = 0) Then
Exit While
ElseIf (i = j + 1) Then
[Link](i)
End If
j=j+1
End While
i=i+1
End While
[Link]()
End Sub
End Module
OUTPUT:
[Type text]
[Type text]
2. Write a program using While statement to print even-odd numbers between 1 to 50.
Module Module1
Sub Main()
Dim i As Integer = 1
While (i <= 50)
If ((i Mod 2) = 0) Then
[Link](i & " Even")
Else
[Link](i & " Odd")
End If
i=i+1
End While
[Link]()
End Sub
End Module
Output:
[Type text]
[Type text]
Practical No 07
Program Code
Write a program using For & For Each loop in [Link]
Program – Program to calculate search the element in an array using linear search.
Module Module1
Sub Main()
Dim Array() As Integer = {12, 34, 56, 37, 78, 53, 98, 22, 19, 68}
Dim Key As Integer
Dim IsKeyFoundFlag As Boolean = False
[Link]("Enter element to search: ")
Key = [Link]()
For i As Integer = 1 To [Link]() - 1
If Array(i) = Key Then
IsKeyFoundFlag = True
End If
Next
If IsKeyFoundFlag = True Then
[Link]("Element present.")
Else
[Link]("Element absent.")
End If
Results (output of the program) :
Enter element to search:
53
Element present
[Type text]
[Type text]
3. .Write program using For Next loop statement tot find the Armstrong
numbers between 1 to 500. (153 is Armstrong Number – 13 + 53 + 33 = 153)
Module Module1
Sub Main()
Dim i As Integer
[Link]("Armstrong Numbers between 1 to 500: ")
For i = 1 To 500 Step 1
Dim sum, num, digit As Integer
sum = 0
num = i
While (num > 0)
digit = num Mod 10
sum += (digit * digit * digit)
num = num \ 10
End While
If (sum = i) Then
[Link](i)
End If
Next
[Link]()
End Sub
End Module
Output :
1
153
370
371
407
[Type text]
[Type text]
Practical No 08
Program Code :
Write a program to demonstrate the use of Button, Textbox and Label.
Public Class Form1
Private Function Factorial(ByVal num As Integer) As Long
Dim fact As Long = 1
Dim i As Integer
For i = 1 To num
fact *= i
Next
Factorial = fact
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
Dim fact As Long
fact = Factorial([Link])
[Link]("Factorial of " & [Link] &
" is " & fact, "Factorial", [Link],
[Link])
End Sub
End Class
[Type text]
[Type text]
Results (output of the program)
1.
[Type text]
[Type text]
2. Write a program to perform the arithmetic operations using controls Label, Button and
TextBox.
Public Class Form1
Dim n As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
n = Val([Link]) + Val([Link])
[Link] = n
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]
n = Val([Link]) - Val([Link])
[Link] = n
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles [Link]
n = Val([Link]) * Val([Link])
[Link] = n
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles [Link]
n = Val([Link]) / Val([Link])
[Link] = n
End Sub
End Class
Output:
[Type text]
[Type text]
3. Write a program to change the background color of the form when user clicks on
different buttons.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
[Link] = [Link]
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]
[Link] = [Link]
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles [Link]
[Link] = [Link]
End Sub
End Class
Output:
[Type text]
[Type text]
Practical No 09
Program Code :
Write a program to demonstrate the use of CheckBox and RadioButton.
Code to check Radio Buttons State
Public Class Form1
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles
[Link]
If ([Link] = True) Then
[Link]("You are Select [Link]")
End If
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles
[Link]
If ([Link] = True) Then
[Link]("You are Select JAVA")
End If
End Sub
End Class
Output :
[Type text]
[Type text]
Code to display message when the checkbox is checked -
Public Class Form1
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles
[Link]
[Link]("you are select [Link]")
End Sub
Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles
[Link]
[Link]("you are select JAVA")
End Sub
End Class
OUTPUT :
[Type text]
[Type text]
1. Write the program using RadioButton to change the bulb state ON/OFF.
Public Class Form1
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles
[Link]
[Link]()
[Link]()
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles
[Link]
[Link]()
[Link]()
End Sub
End Class
OUTPUT:
[Type text]
[Type text]
1. Write a program to change the ForeColor of the text in Label using different RadioButtons
such Red, Green, Blue.
Public Class Form1
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles
[Link]
[Link] = [Link]
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles
[Link]
[Link] = [Link]
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles
[Link]
[Link] = [Link]
End Sub
End Class
OUTPUT:
[Type text]
[Type text]
Practical No 10
Program Code
1. Write a program to demonstrate the use of ListBox and ComboBox.
(Code for Add Items to ListBox & Remove Selected Item from ListBox)
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles [Link]
[Link]([Link])
[Link] = ""
[Link]()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles [Link]
[Link]([Link])
End Sub
End Class
Results (output of the program) :
[Type text]
[Type text]
1. Write the program to select multiple subjects using ListBox control.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]
[Link] = [Link]
[Link]("C")
[Link]("C++")
[Link]("JAVA")
[Link](".NET")
[Link]("PHP")
[Link]("Python")
End Sub
End Class
Output :
[Type text]
[Type text]
2. Write the program to select colleges using single ComboBox.
Public Class Combo_Box
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles [Link]
[Link]("MET")
[Link]("GGSP")
[Link]("KKW")
[Link]("GP")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles [Link]
MsgBox([Link])
End Sub
End Class
OUTPUT:
[Type text]
[Type text]
Exercise :
1. Write a program to select multiple subjects for single semester.
Public Class Student_Registration
Private Sub Student_Registration_Load(sender As Object, e As EventArgs) Handles
[Link]
[Link]("First Semester")
[Link]("Second Semester")
[Link]("Third Semester")
[Link]("Fourth Semester")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles [Link]
If ([Link] = 0) Then
[Link]()
[Link]("Chemistry")
[Link]("Physics")
[Link]("Maths")
[Link]("English")
End If
If ([Link] = 1) Then
[Link]()
[Link]("PIC")
[Link]("Maths")
[Link]("CHM")
[Link]("WPD")
End If
If ([Link] = 2) Then
[Link]()
[Link]("DBM")
[Link]("OOP")
[Link]("CGR")
[Link]("DSU")
End If
If ([Link] = 3) Then
[Link]()
[Link]("JPR")
[Type text]
[Type text]
[Link]("DCC")
[Link]("GUI")
[Link]("SEN")
End If
End Sub
End Class
Output :
[Type text]
[Type text]
[Type text]