KEMBAR78
Public Class Private As Integer Private Sub Byval As Object Byval As Handles | PDF | Software | Software Engineering
0% found this document useful (0 votes)
7 views9 pages

Public Class Private As Integer Private Sub Byval As Object Byval As Handles

The document contains multiple VB.NET program examples demonstrating various programming concepts such as event handling, image lists, rich text boxes, menus with built-in dialogs, exception handling, functions, polymorphism, and inheritance. Each example includes source code and describes its functionality. The programs cover a range of topics suitable for beginners to understand basic programming principles in VB.NET.

Uploaded by

nallamanibca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views9 pages

Public Class Private As Integer Private Sub Byval As Object Byval As Handles

The document contains multiple VB.NET program examples demonstrating various programming concepts such as event handling, image lists, rich text boxes, menus with built-in dialogs, exception handling, functions, polymorphism, and inheritance. Each example includes source code and describes its functionality. The programs cover a range of topics suitable for beginners to understand basic programming principles in VB.NET.

Uploaded by

nallamanibca
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

Write a Program to count number of times the click event occurs

Source Code:

Public Class Form1


Private clickCount As Integer = 0
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles
Button1.Click
clickCount += 1
Label1.Text = "Number of Clicks: " & clickCount.ToString()
End Sub
End Class

Output:
2. Write a program using image lists

Source Code

Public Class Form1


Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles
MyBase.Load
ImageList1.Images.Add(My.Resources.Image1)
ImageList1.Images.Add(My.Resources.Image2)
ImageList1.Images.Add(My.Resources.Image3)
ListView1.LargeImageList = ImageList1
For i As Integer = 0 To ImageList1.Images.Count - 1
Dim item As New ListViewItem("Item " & (i + 1), i)
ListView1.Items.Add(item)
Next
End Sub
End Class

Output:
3.Write a program using rich textbox control

Source Code

Public Class Form1


Private Sub button_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
MessageBox.Show("Entered text:" & RichTextBox1.Text, "Text Display")
End Sub
End Class

Output:
4.Write a program using Menus and Built-in Dialogs

Source Code

Imports System.IO
Public Class Form1

Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles OpenToolStripMenuItem.Click
Dim openfiledialog As New OpenFileDialog()
openfiledialog.Filter = "Textfiles|*.txt|all files|*.*"
openfiledialog.Title = "select a text file"
If openfiledialog.ShowDialog() = DialogResult.OK Then
Dim filepath As String = openfiledialog.FileName
Dim filecontents As String = File.ReadAllText(filepath)
MessageBox.Show("file contents:" & filecontents, "file opened successfully",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

End Sub

Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles SaveToolStripMenuItem.Click
Dim savefiledialog As New SaveFileDialog()
savefiledialog.Filter = "Textfiles|*.txt|all files|*.*"
savefiledialog.Title = "save the text file"
If savefiledialog.ShowDialog() = DialogResult.OK Then
Dim filepath As String = savefiledialog.FileName
File.WriteAllText(filepath, "this is a sample text saved using savefiledialog in
VB.NET.")
MessageBox.Show("file saved successfully", "file saved", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ExitToolStripMenuItem.Click
End

End Sub

Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles NewToolStripMenuItem.Click
Dim f2 As New Form1

f2.Show()
End Sub
End Cla
Output:
5. Write a program using Exception Handling
Source Code

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Try
Dim dividend As Integer = Convert.ToInt32(TextBox1.Text)
Dim divisor As Integer = Convert.ToInt32(TextBox2.Text)
Dim result As Integer = dividend / divisor
MessageBox.Show("Result" & result.ToString(), "Division Successfully(")
Catch ex As DivideByZeroException
MessageBox.Show("Error Division by Zero is not allowed.","error")
Catch ex As FormatException
MessageBox.Show("Error please enter valid integervalues.", "error")
Catch ex As Exception
MessageBox.Show("An unexpected error occurred:." &ex.Message, "error")
End Try
End Sub
End Class
6. Write a program using Function

Module Module1
Sub Main()
Dim num1, num2 As Integer
Console.WriteLine("Enter two number:")
num1 = Convert.ToInt32(Console.ReadLine())
num2 = Convert.ToInt32(Console.ReadLine())
Dim sum As Integer = addnumbers(num1, num2)
Console.WriteLine("Sum of the two numbers is:" & sum)
Dim product As Integer = multiplynumbers(num1, num2)
Console.WriteLine("Product of the two numbers is:" & product)
Console.ReadLine()
End Sub
Function addnumbers(ByVal num1 As Integer, ByVal num2 As Integer)As Integer
Return num1 + num2
End Function
Function multiplynumbers(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
Return num1 * num2
End Function
End Module

Output:
7. Write a program deploying Polymorphism using VB.NET
Public Class Animal
Public Overridable Sub MakeSound()
Console.WriteLine("Animal makes a sound")
End Sub
End Class
Public Class Dog
Inherits Animal
Public Overrides Sub MakeSound()
Console.WriteLine("Dog barks")
End Sub
End Class
Public Class Cat
Inherits Animal
Public Overrides Sub MakeSound()
Console.WriteLine("Cat meows")
End Sub
End Class
Module Program
Sub Main()
Dim myAnimals As New List(Of Animal)
myAnimals.Add(New Dog())
myAnimals.Add(New Cat())
For Each animal As Animal In myAnimals
animal.MakeSound()
Next
Console.WriteLine("Press any Key to Exit...")
Console.ReadKey(True)
End Sub
End Module

Output:
8. Write a program developing Inheritance using VB.NET

Module Module1
Sub Main()
Dim s As New student
s.branch()
s.year()
Console.ReadLine()
End Sub
Class faculty
Dim b As String = "Computer"
Sub branch()
Console.WriteLine("Branch = " & b)
End Sub
End Class
Class student
Inherits faculty
Dim y As String = "Third Year"
Sub year()
Console.WriteLine("Year = " & y)
End Sub
End Class
End Module

Output

You might also like