1.
Design an application to open a text file, modify it and save the changes using built in
dialog boxes.
2. Write a program to perform various arithmetic operations and implement exception
handling.
3. Design a Student Registration Application to store the student data in the database
using ADO.Net.
Examination:
 1. One Question has to be given from the above list (Carries 45 Marks).
 2. One more question has to be given by the examiner by his choice and that question
 need not be in the list (Carries 35 Marks). Student has to answer and execute both
 questions.
Marks Distribution:
Criteria Marks
Question from The List Examiner’s Question
Practical
Proper
Writing Program 25 20
Execution 20 15
Total 80
IA-Viva/Report 20
Total 100
You tube links
For Free Video classes on VB .Net Visit below link
https://www.youtube.com/playlist?list=PLgfNsCf7RQxdAG3_-RyIjaGO09rI8WFlA
1. Write a program to convert a given temperature from Fahrenheit to Celsius and viceversa.
Module Module1
 Sub Main()
 Dim temp As Integer
 Dim tempF As Decimal
 Dim tempC As Integer
 Console.Write("Enter tempaerature: ")
 temp = CInt(Console.ReadLine())
 tempF = CDec(((temp - 32) * 5) / 9)
 tempC = ((tempF - 32) / 1.8)
 Console.WriteLine("Given temp: {0}", temp)
 Console.WriteLine("Given temp to Fahrenheit: {0}", tempF)
 Console.WriteLine("Fahrenheit to Celcius: {0}", tempC)
 Console.ReadLine()
 End Sub
End Module
OUTPUT
2. Write a program to accept roll number, name, marks in 2 subjects of a student
and calculate total,average and display the grade. (using nested if)
Module Module1
 Sub Main()
 Dim rollNo As Integer
 Dim name As String
 Dim mark1 As Integer
 Dim mark2 As Integer
 Dim total As Integer
 Dim average As Decimal
 Dim grade As String
 Console.Write("Enter RollNo: ")
 rollNo = CInt(Console.ReadLine())
 Console.Write("Enter Name: ")
 name = Console.ReadLine()
 Console.Write("Enter Mark1(Max marks 100): ")
 mark1 = CInt(Console.ReadLine())
 Console.Write("Enter Mark2(Max marks 100): ")
 mark2 = CInt(Console.ReadLine())
 total = mark1 + mark1
 average = total / 2
 If (average > 90) Then
 grade = "A"
 ElseIf (average > 70) Then
 grade = "B"
 ElseIf (average > 50) Then
 grade = "C"
 ElseIf (average > 35) Then
 grade = "D"
 Else
 grade = "E"
 End If
 Console.WriteLine("***Entered Details***")
 Console.WriteLine("RollNo:{0}", rollNo)
 Console.WriteLine("Name:{0}", name)
 Console.WriteLine("Mark1:{0}", mark1)
 Console.WriteLine("Mark2:{0}", mark2)
 Console.WriteLine("Total:{0}", total)
 Console.WriteLine("Average:{0}", average)
 Console.WriteLine("Grade:{0}", grade)
 Console.ReadLine()
 End Sub
End Module
OUTPUT
3. Write a program to generate n random numbers .( using rnd() function)
Module Module1
 Sub Main()
 Dim range As Integer
 Dim a As Byte
 Console.Write("Enter no of random numbers you want: ")
 range = CInt(Console.ReadLine())
 Randomize()
 For a = 1 To range
 Console.WriteLine(CInt(range * Rnd()) + 1)
 Next
 Console.ReadLine()
 End Sub
End Module
OUTPUT
4. Write a program to find frequency of a given character in a string .( using for each
loop) Module Module1
 Sub Main()
 Dim ipString As String
 Dim ipChar As String
 Dim singleChar As Char
 Dim charFreq As Integer
 Console.Write("Enter Name: ")
 ipString = Console.ReadLine()
 Console.Write("Enter the char to search:")
 ipChar = Console.ReadLine()
 For Each singleChar In ipString
 If (singleChar = ipChar) Then
 charFreq = charFreq + 1
 End If
 Next
 Console.WriteLine("Frequencey of {0} is :{1}", ipChar, charFreq)
 Console.ReadLine()
 End Sub
End Module
OUTPUT:
5. Write a program to accept array elements and find the minimum and maximum among
them.
Module Module1
 Sub Main()
 Dim n, i, min, max As Integer
 Console.Write("Enter the number of Elements : ")
 n = CInt(Console.ReadLine())
 Dim arr(n) As Integer
 For i = 0 To n - 1
 Console.Write("Enter the " & (i + 1).ToString & "th element: ")
 arr(i) = CInt(Console.ReadLine())
 Next
 Console.WriteLine("Array Contains...")
 For i = 0 To n - 1
 Console.Write(arr(i) & " ")
 Next
 min = arr(0)
 max = arr(0)
 For i = 0 To n - 1
 If arr(i) < min Then
 min = arr(i)
 End If
 Next
 For i = 0 To n - 1
 If arr(i) > max Then
 max = arr(i)
 End If
 Next
 Console.WriteLine()
 Console.WriteLine("Minimum=" & min)
 Console.WriteLine("Maximum=" & max)
 Console.ReadLine()
 End Sub
End Module
OUTPUT:
Journal Programs
1. Design an application to create a login form and validate it using msgbox.
 Public Class Form1
 Dim userName As String
 Dim password As String
 Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles
 btnLogin.Click
 userName = txtUserName.Text
 password = txtPwd.Text
 If (userName = "raghu" And password = "gurumurthy") Then
 MessageBox.Show("Login SuccessFul!, Credentials are Correct")
 Else
 MessageBox.Show("Login Failed!, Credentials are Incorrect")
 End If
 End Sub
 Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles
 btnCancel.Click
 txtUserName.Text = String.Empty
 txtPwd.Text = String.Empty
 End Sub
 End Class
 OUTPUT:
2. Design an application to simulate the working of a font dialog box using combo box.
 Public Class Lab2
 Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
 Dim size As Single
 Dim font As String
 Dim fontStyle As String
 size = CSng(cmbFSize.SelectedItem)
 font = CStr(cmbFont.SelectedItem)
 fontStyle = CStr(cmbFStyle.SelectedItem)
 Select Case fontStyle
 Case "Regular"
 lblSample.Font = New Font(font, size, Drawing.FontStyle.Regular)
 Case "Bold"
 lblSample.Font = New Font(font, size, Drawing.FontStyle.Bold)
 Case "Italic"
 lblSample.Font = New Font(font, size, Drawing.FontStyle.Italic)
 End Select
 If chkStrikeout.Checked Then
 lblSample.Font = New Font(font, size, Drawing.FontStyle.Strikeout)
 chkUnderLine.Checked = False
 End If
 If chkUnderLine.Checked Then
 lblSample.Font = New Font(lblSample.Font.FontFamily, size,
Drawing.FontStyle.Underline)
 chkStrikeout.Checked = False
 End If
 End Sub
 Private Sub Lab2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 cmbFont.SelectedItem = "Arial"
 cmbFStyle.SelectedItem = "Regular"
 cmbFSize.SelectedItem = "8"
 End Sub
 Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
 cmbFont.SelectedItem = "Arial"
 cmbFStyle.SelectedItem = "Regular"
 cmbFSize.SelectedItem = "8"
 chkStrikeout.Checked = False
 chkUnderLine.Checked = False
 lblSample.Font = New Font("Arial", 8, Drawing.FontStyle.Regular)
 End Sub
End Class
OUTPUT:
3. Design a reminder application to schedule a meeting using calendar and input box.
Imports System.IO
Public Class Lab3
 Dim m As MsgBoxResult
 Dim t As String
 Private Sub MonthCalendar1_DateSelected(sender As Object, e As
DateRangeEventArgs) Handles MonthCalendar1.DateSelected
 t = MonthCalendar1.SelectionRange.Start.Month.ToString &
MonthCalendar1.SelectionRange.Start.Day.ToString
 Try
 If File.Exists(t & ".txt") = True Then
 MonthCalendar1.Enabled = False
 MonthCalendar1.Hide()
 TextBox1.Enabled = True
 TextBox1.Show()
 btnSave.Enabled = True
 btnSave.Show()
 btnBack.Enabled = True
 btnBack.Show()
 TextBox1.Text = File.ReadAllText(t & ".txt")
 Else
 m = MsgBox("Would you like to have appointment for this date?",
MsgBoxStyle.YesNo)
 If m = MsgBoxResult.Yes Then
 MonthCalendar1.Enabled = False
 MonthCalendar1.Hide()
 TextBox1.Enabled = True
 TextBox1.Show()
 TextBox1.Text = ""
 btnSave.Enabled = True
 btnSave.Show()
 btnBack.Enabled = True
 btnBack.Show()
 End If
 End If
 Catch ex As Exception
 MsgBox(ex.Message)
 End Try
 End Sub
 Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
 Try
 If TextBox1.Text = "" Then
 If File.Exists(t & ".txt") = True Then
 File.Delete(t & ".txt")
 End If
 End If
 If TextBox1.Text.Length > 0 Then
 File.WriteAllText(t & ".txt", TextBox1.Text)
 End If
 Catch ex As Exception
 MsgBox(ex.Message)
 End Try
 End Sub
 Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
 TextBox1.Enabled = False
 TextBox1.Hide()
 btnSave.Enabled = False
 btnSave.Hide()
 btnBack.Enabled = False
 btnBack.Hide()
 MonthCalendar1.Enabled = True
 MonthCalendar1.Show()
 End Sub
 Private Sub Lab3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 Dim m1 As MsgBoxResult
 t = MonthCalendar1.SelectionRange.Start.Month.ToString &
MonthCalendar1.SelectionRange.Start.Day.ToString
 If Date.Today = MonthCalendar1.TodayDate And File.Exists(t & ".txt") = True Then
 m1 = MsgBox("You have appointments today, wanna view them",
MsgBoxStyle.YesNo)
 If m1 = MsgBoxResult.Yes Then
 MonthCalendar1.Enabled = False
 MonthCalendar1.Hide()
 TextBox1.Enabled = True
 TextBox1.Show()
 btnSave.Enabled = True
 btnSave.Show()
 btnBack.Enabled = True
 btnBack.Show()
 TextBox1.Text = File.ReadAllText(t & ".txt")
 End If
 End If
 End Sub
End Class
OUTPUT:
4. Design a screen saver application using timer control.
Public Class Form41
 Private Function MarqueeText(ByVal Data As String)
 Dim S1 As String = Data.Remove(0, 1)
 Dim S2 As String = Data(0)
 Return S1 & S2
 End Function
 Private Sub Form41_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 Timer1.Start()
 End Sub
 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
 Label1.Text = MarqueeText(Label1.Text)
 End Sub
 Private Sub Form41_KeyPress(sender As Object, e As KeyPressEventArgs) Handles
MyBase.KeyPress
 Timer1.Stop()
 End Sub
 Private Sub Form41_MouseHover(sender As Object, e As EventArgs) Handles
MyBase.MouseHover
 Timer1.Stop()
 End Sub
End Class
OUTPUT:
5. Design an application to create an MDI form having a menu with options- programs and
exit. The program menu should have sub menu items that calls separate child forms such as
Fibonacci and factorial.
Parent Form
Public Class Lab5
 Private Sub FactorialToolStripMenuItem_Click(sender As Object, e As EventArgs)
Handles FactorialToolStripMenuItem.Click
 Lab51.MdiParent = Me
 Lab51.Show()
 End Sub
 Private Sub FibnociiToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
FibnociiToolStripMenuItem.Click
 Lab52.MdiParent = Me
 Lab52.Show()
 End Sub
End Class
Child Form: 1
Public Class Lab51
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 Dim num As Integer
 Dim i As Integer
 Dim fact As Integer
 num = CInt(TextBox1.Text)
 fact = 1
 For i = 1 To num
 fact = fact * i
 Next
 Label2.Visible = True
 Label2.Text = "Factorial of given range: " + CStr(fact)
 End Sub
 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
 Label2.Visible = False
 Label2.Text = String.Empty
 TextBox1.Text = String.Empty
 End Sub
End Class
Child Form: 2
Public Class Lab52
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 Dim num As Integer
 Dim i As Integer
 Dim a As Integer
 Dim b As Integer
 Dim c As Integer
 a=0
 b=1
 num = CInt(TextBox1.Text)
 Label2.Text = "Fib Series of Given range:" & Environment.NewLine
 Label2.Visible = True
 For i = 1 To num
 Label2.Text += CStr(a) & Environment.NewLine
 c=a+b
 a=b
 b=c
 Next
 End Sub
 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
 TextBox1.Text = String.Empty
 Label2.Text = String.Empty
 Label2.Visible = False
 End Sub
End Class
OUTPUT:
Parent Form
Child Form1
Child Form 2
6. Design an Pizza Order application using check box and radio buttons and also generate a
bill for the same.
Public Class Lab6
 Dim valid As Boolean
 Dim price As Integer
 Dim strbill As String
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 If ValidateForm() Then
 If CalculatePrice() <> 0 Then
 Label1.Text = "Price:" + CStr(price)
 FillBillString()
 MessageBox.Show(strbill)
 End If
 End If
 End Sub
 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
 Button2.Click TextBox1.Text = String.Empty
 CheckBox1.Checked = False
 CheckBox2.Checked = False
 Label1.Text = False
 End Sub
 Private Function ValidateForm() As Boolean
 valid = True
 If RadioButton1.Checked Or RadioButton2.Checked Or RadioButton3.Checked Then
 valid = True
 Else
 MessageBox.Show("Size is not selected")
 valid = False
 Return valid
 End If
 If TextBox1.Text = String.Empty Then
 MessageBox.Show("Address is manadatory")
 valid = False
 Return valid
 End If
 Return valid
 End Function
 Private Function CalculatePrice() As Integer
 price = 0
 If CheckBox1.Checked Then
 price += 20
 End If
 If CheckBox2.Checked Then
 price += 20
 End If
 If RadioButton1.Checked Then
 price += 50
 ElseIf RadioButton2.Checked Then
 price += 70
 ElseIf RadioButton3.Checked Then
 price += 90
 End If
 Return price
 End Function
 Private Function FillBillString() As String
 strbill = "Pizza Order Bill" & Environment.NewLine
 strbill += "Adress" & Environment.NewLine
 strbill += TextBox1.Text & Environment.NewLine
 If CheckBox1.Checked Or CheckBox2.Checked Then
 strbill += "Extra addons" & Environment.NewLine
 If CheckBox1.Checked Then
 strbill += "Cheese(Rs 20)" & Environment.NewLine
 End If
 If CheckBox2.Checked Then
 strbill += "Topings(Rs 20)" & Environment.NewLine
 End If
 End If
 strbill += "Size" & Environment.NewLine
 If RadioButton1.Checked Then
 strbill += "Small(Rs 50)" & Environment.NewLine
 ElseIf RadioButton2.Checked Then
 strbill += "Medium(Rs 70)" & Environment.NewLine
 ElseIf RadioButton3.Checked Then
 strbill += "Large(Rs 90)" & Environment.NewLine
 End If
 strbill += "Price" + CStr(price) & Environment.NewLine
 strbill += "Thanks for Shopping with us"
 Return strbill
 End Function
End Class
OUTPUT:
Before Order Placing
After Order Placing
7. Design a color pallet application using scroll bars.
Public Class Lab7
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 Me.BackColor = Label4.BackColor
 End Sub
 Private Sub HScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles
HScrollBar1.Scroll, HScrollBar2.Scroll, HScrollBar3.Scroll
 Label4.BackColor = Color.FromArgb(HScrollBar1.Value,
HScrollBar2.Value, HScrollBar3.Value)
 NumericUpDown1.Value = HScrollBar1.Value
 NumericUpDown2.Value = HScrollBar2.Value
 NumericUpDown3.Value = HScrollBar3.Value
 End Sub
End Class
OUTPUT:
Before Applying BG Colour
After Applying BG Colour
 VB .Net Lab
8. Design an application which calculates EMI of a loan using functions.
Public Class Lab8
 Dim principalAmount As Integer
 Dim timeInMonths As Integer
 Dim rateOfIntrest As Integer
 Dim simpleIntrest As Integer
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 Dim calculatedEMI As Integer
 calculatedEMI = CalculateEMI()
 MessageBox.Show("Total EMI: " + CStr(calculatedEMI) + " Rs")
 End Sub
 Private Function CalculateIntrest() As Integer
 principalAmount = CInt(TextBox1.Text)
 rateOfIntrest = CInt(TextBox2.Text)
 timeInMonths = CInt(TextBox3.Text)
 If RadioButton2.Checked Then
 timeInMonths = (TextBox3.Text) * 12
 End If
 simpleIntrest = (principalAmount * timeInMonths * rateOfIntrest) / 100
 Return simpleIntrest
 End Function
 Private Function CalculateEMI() As Integer
 Dim totalAmount As Integer
 Dim totalEMI As Integer
 totalAmount = CInt(TextBox1.Text) + CalculateIntrest()
 totalEMI = totalAmount / timeInMonths
 Return totalEMI
 End Function
End Class
OUTPU
 2 Raghu Gurumurthy, MCA (Site : www.isat.guru www.raghug.in, Phone no:
 VB .Net Lab
9. Design an application to implement various string operations such as reversing, case
conversion,length, concatenation.
Public Class Lab9
 Dim enteredString As String
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 enteredString = TextBox1.Text
 MessageBox.Show("Reverse of given string: " + StrReverse(enteredString))
 End Sub
 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
 enteredString = TextBox1.Text
 If (CheckBox1.Checked) Then
 MessageBox.Show("Lowercase string: " + enteredString.ToLower())
 Else
 MessageBox.Show("Uppercase string: " + enteredString.ToUpper())
 End If
 End Sub
 Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
 enteredString = TextBox1.Text
 MessageBox.Show("String length: " + CStr(enteredString.Length()))
 End Sub
 Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
 enteredString = TextBox1.Text
 Dim strToConcatenate = TextBox2.Text
 MessageBox.Show("String Concatenation: " + String.Concat(enteredString,
strToConcatenate))
 End Sub
End Class
OUTPU
 2 Raghu Gurumurthy, MCA (Site : www.isat.guru www.raghug.in, Phone no:
 VB .Net Lab
10. Write a program to accept sides of a triangle and then find its area, perimeter and type of
triangle using classes (OOP).
For Triangle reference visit below link
https://www.mathwarehouse.com/geometry/triangles/triangle-types.php
Public Class Lab10
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 Dim objTriangle1 As Triangle = New Triangle()
 objTriangle1.side1 = CInt(TextBox1.Text)
 objTriangle1.side2 = CInt(TextBox2.Text)
 objTriangle1.side2 = CInt(TextBox3.Text)
 objTriangle1.angle1 = CInt(TextBox4.Text)
 objTriangle1.angle2 = CInt(TextBox5.Text)
 objTriangle1.angle2 = CInt(TextBox6.Text)
 Dim objTriangle2 As Triangle = New Triangle(objTriangle1)
 MessageBox.Show("Perimter:" + CStr(objTriangle2.perimeterOfTriangle()) &
Environment.NewLine + "Area: " + CStr(objTriangle2.areaOfTriangle()) &
Environment.NewLine + "Type of Triangle :" + CStr(objTriangle2.whatKindOfTriangle()))
 End Sub
End Class
Triangle Class
Public Class Triangle
 Public angle1 As Integer
 Public angle2 As Integer
 Public angle3 As Integer
 Public side1 As Integer
 Public side2 As Integer
 Public side3 As Integer
 Public Sub New()
 End Sub
 Public Sub New(objTri As Triangle)
 angle1 = objTri.angle1
 2 Raghu Gurumurthy, MCA (Site : www.isat.guru www.raghug.in, Phone no:
 VB .Net Lab
 angle2 = objTri.angle2
 angle3 = objTri.angle3
 side1 = objTri.side1
 side2 = objTri.side2
 side3 = objTri.side3
 End Sub
 Public Function areaOfTriangle() As Integer
 Dim perimeter As Integer
 Dim area As Integer
 perimeter = perimeterOfTriangle()
 area = Math.Sqrt(perimeter * (perimeter - side1) * (perimeter - side2) * (perimeter -
side3))
 Return area
 End Function
 Public Function perimeterOfTriangle() As Integer
 Dim perimeter As Integer
 perimeter = side1 + side2 + side3
 Return perimeter
 End Function
 Public Function whatKindOfTriangle() As String
 Dim kindOfTriangle As String
 kindOfTriangle = "Not Defined"
 If (angle1 = 90 Or angle2 = 90 Or angle2 = 90) Then
 kindOfTriangle = "Right Angle Triangles"
 ElseIf angle1 = angle2 = angle2 Then
 kindOfTriangle = "Equilateral Triangle"
 ElseIf ((angle1 = angle2) Or (angle2 = angle3) Or (angle1 = angle3)) Then
 kindOfTriangle = "Isosceles Triangle"
 ElseIf ((side1 = side2) Or (side2 = side3) Or (side1 = side3)) Then
 kindOfTriangle = "Scalene Triangle"
 ElseIf ((side1 = side2) Or (side2 = side3) Or (side1 = side3)) Then
 kindOfTriangle = "Scalene Triangle"
 ElseIf (angle1 < 90 And angle2 < 90 And angle2 < 90) Then
 kindOfTriangle = "Acute Triangle"
 End If
 Return kindOfTriangle
 End Function
End Class
OUTPUT:
 2 Raghu Gurumurthy, MCA (Site : www.isat.guru www.raghug.in, Phone no:
 VB .Net Lab
11. Design an application to open a text file, modify it and save the changes using built in
dialog boxes.
Public Class Lab11
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 SaveFileDialog1.ShowDialog()
 SaveFileDialog1.Title = "SAVE TEXT"
 SaveFileDialog1.InitialDirectory = "D:\SavedContent"
 Dim location As String
 location = SaveFileDialog1.FileName
 If System.IO.File.Exists(location) Then
 My.Computer.FileSystem.WriteAllText(location, "" & TextBox1.Text, True)
 Else
 My.Computer.FileSystem.WriteAllText(location & ".txt", "" & TextBox1.Text, True)
 End If
 End Sub
 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
 OpenFileDialog1.InitialDirectory = "D:\SavedContent"
 If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
 TextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
 End If
 End Sub
 Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
 TextBox1.Text = String.Empty
 End Sub
End Class
OUTPUT:
 2 Raghu Gurumurthy, MCA (Site : www.isat.guru www.raghug.in, Phone no:
 VB .Net Lab
Before Writing To Text File
While Writing to text file
While Opening to text file
 2 Raghu Gurumurthy, MCA (Site : www.isat.guru www.raghug.in, Phone no:
 VB .Net Lab
12. Write a program to perform various arithmetic operations and implement exception
handling.
Public Class Lab12
 Dim result As String
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click,
Button2.Click, Button3.Click, Button4.Click, Button5.Click
 Try
 Dim operand1 As Integer
 Dim operand2 As Integer
 operand1 = TextBox1.Text
 operand2 = TextBox2.Text
 Dim clickedButton = TryCast(sender, Button)
 If clickedButton IsNot Nothing Then
 Dim tagValue As Integer
 tagValue = CInt(clickedButton.Tag)
 Select Case tagValue
 Case 1
 result = operand1 + operand2
 MessageBox.Show("Sum is:" + CStr(result), "Result")
 Case 2
 result = operand1 - operand2
 MessageBox.Show("Difference is:" + CStr(result), "Result")
 Case 3
 result = operand1 * operand2
 MessageBox.Show("Difference is:" + CStr(result), "Result")
 Case 4
 result = operand1 / operand2
 MessageBox.Show("Quotent is:" + CStr(result), "Result")
 Case 5
 result = operand1 Mod operand2
 MessageBox.Show("Reaminder is:" + CStr(result), "Result")
 2 Raghu Gurumurthy, MCA (Site : www.isat.guru www.raghug.in, Phone no:
 VB .Net Lab
 End Select
 End If
 Catch e1 As
 DivideByZeroException result =
 e1.ToString
 MessageBox.Show("Exception Caught:" + result, "Exception")
 Catch e2 As IO.IOException
 result = e2.ToString
 MessageBox.Show("Exception Caught:" + result, "Exception")
 Catch e3 As InvalidCastException
 result = e3.ToString
 MessageBox.Show("Exception Caught:" + result, "Exception")
 Finally
 MessageBox.Show("Finally Block:" + result, "Finally")
 End Try
 End Sub
End Class
OUTPUT:
13. Design a Student Registration Application to store the student data in the database using
 2 Raghu Gurumurthy, MCA (Site : www.isat.guru www.raghug.in, Phone no:
 VB .Net Lab
ADO.Net.
 2 Raghu Gurumurthy, MCA (Site : www.isat.guru www.raghug.in, Phone no:
 VB .Net Lab
Imports System.Data.SqlClient
Public Class Lab13
 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 If AddStudent() > 0 Then
 MessageBox.Show("Student record inserted succesfully", "Result")
 Else
 MessageBox.Show("Error occured during Student record insertion", "Result")
 End If
 End Sub
 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
 Button2.Click TextBox1.Text = String.Empty
 TextBox2.Text = String.Empty
 TextBox3.Text = String.Empty
 TextBox4.Text = String.Empty
 RadioButton2.Checked = True
 End Sub
 Private Function AddStudent() As Integer
 Dim con As New SqlConnection
 Dim cmd As New SqlCommand
 Dim gender As String
 Dim result As Integer
 result = 0
 gender = "Female"
 If RadioButton1.Checked Then
 gender = "Male"
 End If
 Try
 con.ConnectionString = "Data Source=USER-PC\SQLEXPRESS;Initial
Catalog=VBLAB;Integrated Security=True"
 con.Open()
 cmd.Connection = con
 cmd.CommandText = "INSERT INTO
Student(NAME,USN,ADDRESS,GENDER,BGROUP) VALUES('" + TextBox1.Text + "','" +
TextBox2.Text + "','" + TextBox3.Text + "','" + gender + "','" + TextBox4.Text + "')"
 result = cmd.ExecuteNonQuery()
 Catch ex As Exception
 MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert
Records")
 Finally
 con.Close()
 End Try
 Return result
 End Function
End Class
OUTPUT:
 3 Raghu Gurumurthy, MCA (Site : www.isat.guru www.raghug.in, Phone no:
 VB .Net Lab
3 Raghu Gurumurthy, MCA (Site : www.isat.guru www.raghug.in, Phone no: