0% found this document useful (0 votes)
7 views

VB.NET PROGRAMS

The document provides various VB.NET programming examples, including class creation, volume calculation, average display using combo boxes, and demonstrating constructors and destructors. It also covers inheritance, method overloading, and overriding concepts. Each example includes code snippets and expected outputs for better understanding.

Uploaded by

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

VB.NET PROGRAMS

The document provides various VB.NET programming examples, including class creation, volume calculation, average display using combo boxes, and demonstrating constructors and destructors. It also covers inheritance, method overloading, and overriding concepts. Each example includes code snippets and expected outputs for better understanding.

Uploaded by

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

Programs of Vb.

Net
Develop a program to create class. Access
members of class using its object.
Module Module1
Sub Main()
Dim obj As New Test 'creating a object obj for Test Class
obj.disp() 'Calling the disp method using obj
Console.ReadLine()
End Sub
End Module
Public Class Test
Sub disp()
Console.WriteLine("Welcome to VB.NET")
End Sub
End Class
1. Write a program to identify Volume of Box Class, with three
data members, length, breadth and height.
Class Box
Module Module1
Public l, b, h As Integer
Sub Main()
Function volume(ByVal i As Integer, ByVal j As Integer, ByVal k As
Dim obj As Box = New Box() Integer)
Dim vol As Integer Dim v As Integer
vol = obj.volume(2, 4, 4) l=i
Console.WriteLine("Length =" & obj.l) b=j
Console.WriteLine("Breadth =" & obj.b) h=k
Console.WriteLine("Height =" & obj.h) v=l*b*h
Console.WriteLine("Volume =" & vol) Return v
Console.ReadLine() End Function
End Sub End Class
End Module
Implement a program to accept values from Combo Box and
Display average of this in message box using class.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Items.Add(5)
ComboBox1.Items.Add(8)
ComboBox2.Items.Add(6)
ComboBox2.Items.Add(11)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim average As double = (Val(ComboBox1.Text) + Val(ComboBox2.Text)) / 2
MsgBox("Average = " & average)
End Sub
End Class
Write a program to demonstrate the use of constructor &
destructor
Module1
Sub Main() OUTPUT:
Constructor Executed
Dim obj As New test
This is base class
obj.show()
Console.ReadLine()
End Sub
Public Class test
Public Function show()
Console.WriteLine("This is base class")
End Function
Sub New()
Console.WriteLine("Constructor Executed")
End Sub
End Class
End Module
Module Module1
Sub Main() OUTPUT: This is base class
Dim obj As New test Destructor executing here
obj.show()
End Sub
End Module
Public Class test
Public Function show()
Console.WriteLine("This is base Class")
End Function
Protected Overrides Sub Finalize()
Console.WriteLine("Destructor executing here")
Console.ReadLine()
End Sub
End Class
1. Implement a program to display any message at run
time.(Using Constructor).
Module Module1
Sub Main()
Dim obj As New sample
obj.display()
Console.ReadLine()
End Sub
Class sample
Public Sub New()
Console.WriteLine("This is Constructor")
End Sub
Sub display()
Console.WriteLine("This is Method")
End Sub
End Class
End Module
2. Implement a program to calculate area of circle using
parameterized constructor.
Module Module1 Class circle
Dim p As Double = 3.14
Sub Main()
Dim r, a As Double
Dim obj As New circle(2) Public Sub New(ByVal i As Integer)
obj.area() r=i
Console.ReadLine() End Sub
End Sub Sub area()
a=p*r*r
Console.WriteLine("Area of Circle = " & a)
End Sub
End Class
OUTPUT: Area of Circle = 12.56 End Module
Develop a Program for Inheritance
Module Module1
Sub Main()
Dim obj As New details
obj.show()
Console.ReadLine()
End Sub
End Module
Public Class student 'Base Class
Public branch As String = "Computer"
End Class
Public Class details Inherits student 'Derived Class
Public Function show()
Console.WriteLine("Branch = " & branch)
Return 0
End Function
End Class
Implement a program for inheritance where Student is Child Class and faculty is Base
class.(Take Appropriate variable in Base and Child class)
Sub Main()
Module Module1
Dim s As New student
Class faculty
s.branch()
Sub branch()
Dim b As String = "Computer" s.year()
Console.WriteLine("Branch = " & b) Console.ReadLine()
End Sub End Sub
End Class End Module
Class student Inherits faculty
Sub year()
Dim y As String = "Second Year"
Console.WriteLine("Year = " & y)
End Sub
End Class
Implement a Program for Overloading &
overriding
Imports System
Module Program
Class c1
Overridable Sub hi()
Console.WriteLine("Old Method hi")
End Sub
End Class
Class c2
Inherits c1
Shared Sub main()
Dim o As New c2()
o.hi()
End Sub
Overrides Sub hi()
console.writeline("New and Improved method hi")
End Sub
End Class
End Module
Imports System
Module Module1
Class overload
Dim r As Double
Public Overloads Sub area(ByVal r)
Console.Write("Area of the Circle :")
Console.WriteLine(1 / 3 * 3.14 * r * r * r)
End Sub
Dim length As Integer
Dim width As Integer
Public Overloads Sub area(ByVal length, ByVal width)
Console.Write(" Area of the Rectangle :")
Console.WriteLine(length * width)
End Sub
End Class
Sub Main()
Dim r As New overload()
r.area(3.1)
r.area(4, 5)
End Sub
End Module

You might also like