Practical No: 03
Program Code:
Write a program using MessageBox and Arithmetic Expressions –
Module Module1
Dim i, j, r As Integer
Sub Main()
Console.WriteLine("Enter First Value=")
i = Console.ReadLine()
Console.WriteLine("Enter Second Value=")
j = Console.ReadLine()
Console.ReadLine()
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 Button1.Click
n = Val(TextBox1.Text) + Val(TextBox2.Text)
MsgBox("Addition=" & n)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
n = Val(TextBox1.Text) - Val(TextBox2.Text)
MsgBox("Substraction=" & n)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
n = Val(TextBox1.Text) * Val(TextBox2.Text)
MsgBox("Multiplication=" & n)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
n = Val(TextBox1.Text) / Val(TextBox2.Text)
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 Button2.Click
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 Button4.Click
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 Button3.Click
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 Button1.Click
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
Console.WriteLine("Enter a Number")
n = Console.ReadLine()
If (n > 0) Then
Console.WriteLine("Number is Positive")
Else
Console.WriteLine("Number is Negative")
End If
Console.ReadLine()
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
Console.Write("Enter the values of a, b and c:")
a = Val(Console.ReadLine())
b = Val(Console.ReadLine())
c = Val(Console.ReadLine())
If (a > b) Then
If (a > c) Then
Console.WriteLine("Greatest Number is:" & a)
Else
Console.WriteLine("Greatest Number is:" & c)
End If
Else
If (b > c) Then
Console.WriteLine("Greatest Number is:" & b)
Else
Console.WriteLine("Greatest Number is:" & c)
End If
End If
Console.ReadLine()
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()
Console.WriteLine("Enter Number")
i = Console.ReadLine()
If ((i Mod 2) = 0) Then
Console.WriteLine("Number is Even")
Else
Console.WriteLine("Number is Odd")
End If
Console.ReadLine()
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 VB.NET
Module Module1
Sub Main()
Dim grade As String
Console.WriteLine("Enter Your grade")
grade = Console.ReadLine()
Select Case grade
Case "A"
Console.WriteLine("High Distinction")
Case "A-"
Console.WriteLine("Distinction")
Case "B"
Console.WriteLine("Credit")
Case "C"
Console.WriteLine("Pass")
Case Else
Console.WriteLine("Fail")
End Select
Console.ReadLine()
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
Console.WriteLine("Number of vowels: " & numberOfVowels)
Console.ReadKey()
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
Console.WriteLine("Menu:-\n1.Add\n2.Subtract" & _
"\n3.Multiply\n4.Divide\n5.Exit.")
Console.WriteLine("Enter choice: ")
choice = Console.ReadLine()
Console.WriteLine("Enter number 1: ")
N1 = Console.ReadLine()
Console.WriteLine("Enter number 2: ")
N2 = Console.ReadLine()
Select Case choice
Case 1
Result = N1 + N2
Console.WriteLine("Sum = " & Result)
Case 2
Result = N1 - N2
Console.WriteLine("Difference = " & Result)
Case 3
Result = N1 * N2
Console.WriteLine("Product = " & Result)
Case 4
Result = N1 \ N2
Console.WriteLine("Quotient = " & Result)
Result = N1 Mod N2
Console.WriteLine("Remainder = " & Result)
Case 5
Exit Sub
Case Else
Console.WriteLine("Wrong option ...")
End Select
Loop While choice <> 5
End Sub
End Module
Output:
Menu:-\n1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Exit.
Enter choice: 1
Enter number 1: 57
Enter number 2: 87
Sum = 144
Menu:-\n1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Exit.
Enter choice: 5
[Type text]
Practical No 06
Program Code :
Write a program using While & Do loop in VB.Net
For while loop.
Module Module1
Sub Main()
Dim a As Integer =
1 While (a < 10)
Console.WriteLine(
a) a = a + 1
End While
Console.ReadLine()
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
Console.WriteLine(
a) a = a + 1
Loop While (a<10)
Console.ReadLine()
End Sub
End Module
Output:
1
2
3
4
5
6
7
[Type text]
[Type text]
8
9
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
Console.WriteLine(i)
End If
j=j+1
End While
i=i+1
End While
Console.ReadLine()
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
Console.WriteLine(i & " Even")
Else
Console.WriteLine(i & " Odd")
End If
i=i+1
End While
Console.ReadLine()
End Sub
End Module
Output:
[Type text]
[Type text]
Practical No 07
Program Code
Write a program using For & For Each loop in VB.Net
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
Console.WriteLine("Enter element to search: ")
Key = Console.ReadLine()
For i As Integer = 1 To Array.Length() - 1
If Array(i) = Key Then
IsKeyFoundFlag = True
End If
Next
If IsKeyFoundFlag = True Then
Console.WriteLine("Element present.")
Else
Console.WriteLine("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
Console.Write("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
Console.WriteLine(i)
End If
Next
Console.ReadLine()
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 Button1.Click
Dim fact As Long
fact = Factorial(TextBox1.Text)
MessageBox.Show("Factorial of " & TextBox1.Text &
" is " & fact, "Factorial", MessageBoxButtons.OK,
MessageBoxIcon.Information)
[Type text]
[Type text]
End Sub
End Class
Results (output of the program)
[Type text]
[Type text]
1.
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 Button1.Click
n = Val(TextBox1.Text) + Val(TextBox2.Text)
TextBox3.Text = n
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
n = Val(TextBox1.Text) - Val(TextBox2.Text)
TextBox3.Text = n
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
n = Val(TextBox1.Text) * Val(TextBox2.Text)
TextBox3.Text = n
End Sub
[Type text]
[Type text]
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
n = Val(TextBox1.Text) / Val(TextBox2.Text)
TextBox3.Text = n
End Sub
End Class
Output:
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 Button1.Click
Me.BackColor = Color.Red
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.BackColor = Color.Green
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Me.BackColor = Color.Yellow
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
RadioButton1.CheckedChanged
If (RadioButton1.Checked = True) Then
MessageBox.Show("You are Select VB.NET")
End
If End
Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton2.CheckedChanged
If (RadioButton2.Checked = True) Then
[Type text]
[Type text]
MessageBox.Show("You are Select JAVA")
End
If End
Sub
End Class
Output :
Code to display message when the checkbox is checked -
Public Class Form1
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox1.CheckedChanged
MessageBox.Show("you are select VB.NET")
End Sub
Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox2.CheckedChanged
MessageBox.Show("you are select JAVA")
End Sub
[Type text]
[Type text]
End Class
OUTPUT :
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
[Type text]
[Type text]
RadioButton1.CheckedChanged
PictureBox2.Show()
PictureBox1.Hide()
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton2.CheckedChanged
PictureBox1.Show()
PictureBox2.Hide()
End Sub
End Class
OUTPUT:
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
RadioButton1.CheckedChanged
[Type text]
[Type text]
Label1.ForeColor = Color.Red
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton2.CheckedChanged
Label1.ForeColor =
Color.Green End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles
RadioButton3.CheckedChanged
Label1.ForeColor = Color.Blue
End Sub
End Class
OUTPUT:
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)
[Type text]
[Type text]
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
End Class
Results (output of the program) :
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
MyBase.Load ListBox1.SelectionMode = SelectionMode.MultiSimple
ListBox1.Items.Add("C")
ListBox1.Items.Add("C++")
[Type text]
[Type text]
ListBox1.Items.Add("JAVA")
ListBox1.Items.Add(".NET")
ListBox1.Items.Add("PHP")
ListBox1.Items.Add("Python")
End Sub
End Class
Output :
2. Write the program to select colleges using single ComboBox.
Public Class Combo_Box
[Type text]
[Type text]
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("MET")
ComboBox1.Items.Add("GGSP")
ComboBox1.Items.Add("KKW")
ComboBox1.Items.Add("GP")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles ComboBox1.SelectedIndexChanged
MsgBox(ComboBox1.SelectedItem.ToString)
End Sub
End Class
OUTPUT:
Exercise :
1. Write a program to select multiple subjects for single semester.
[Type text]
[Type text]
Public Class Student_Registration
Private Sub Student_Registration_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
ComboBox1.Items.Add("First Semester")
ComboBox1.Items.Add("Second Semester")
ComboBox1.Items.Add("Third Semester")
ComboBox1.Items.Add("Fourth Semester")
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles ComboBox1.SelectedIndexChanged
If (ComboBox1.SelectedIndex = 0) Then
ListBox1.Items.Clear()
ListBox1.Items.Add("Chemistry")
ListBox1.Items.Add("Physics")
ListBox1.Items.Add("Maths")
ListBox1.Items.Add("English")
End If
If (ComboBox1.SelectedIndex = 1) Then
ListBox1.Items.Clear()
ListBox1.Items.Add("PIC")
ListBox1.Items.Add("Maths")
ListBox1.Items.Add("CHM")
ListBox1.Items.Add("WPD")
End If
If (ComboBox1.SelectedIndex = 2) Then
ListBox1.Items.Clear()
ListBox1.Items.Add("DBM")
ListBox1.Items.Add("OOP")
ListBox1.Items.Add("CGR")
ListBox1.Items.Add("DSU")
End If
If (ComboBox1.SelectedIndex = 3) Then
ListBox1.Items.Clear()
ListBox1.Items.Add("JPR")
ListBox1.Items.Add("DCC")
ListBox1.Items.Add("GUI")
ListBox1.Items.Add("SEN")
End
If End
Sub
End Class
Output :
[Type text]