Example : Class object examples in VB .Net to display the area of a rectangle taking corresponding values using Class-Object concept with Form Application in Console Application.
Imports System
Public Class Area_of_Rect
Dim len As Single
Dim wdth As Single
Dim Area1 As Single
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Public Sub Input()
len = 7.5
wdth = 5.5
End Sub
Public Function Process() As Double
Area1 = len * wdth
'Return True
End Function
Public Sub Output()
Console.WriteLine("Length = {0}", len)
Console.WriteLine("Width = {0}", wdth)
Console.WriteLine("Area of Rectangle = {0}", Area1)
End Sub
Shared Sub Main()
Dim obj1 As New Area_of_Rect()
obj1.Input()
obj1.Process()
obj1.Output()
Console.WriteLine()
Console.WriteLine("Press any key to exit from output screen...")
Console.ReadKey()
'Console.ReadLine()
End Sub
End Class
Output:
Length = 7.5
Width = 5.5
Area of Rectangle = 41.25
Press any key to exit from output screen...
------------------ OR ------------------
Imports System
Public Class Area_of_Rect 'Class creation
Dim len As Double ' Variable Declaration
Dim wdth As Double
'Private len As Double
'Private wdth As Double
'Public len As Double
'Public wdth As Double
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Public Sub Input()
len = 7.5
wdth = 5.5
End Sub
Public Function Area() As Double
Area = len * wdth
End Function
Public Sub Output()
Console.WriteLine("Length = {0}", len)
Console.WriteLine("Width = {0}", wdth)
Console.WriteLine("Area of Rectangle = {0}", Area())
End Sub
Shared Sub Main()
Dim obj1 As New Area_of_Rect() ' Object Creation
obj1.Input() ' Calling method using Object
obj1.Output()
'Console.ReadLine()
Console.WriteLine()
Console.WriteLine("Press any key to exit from output screen...")
Console.ReadKey()
End Sub
End Class
Output:
Length = 7.5
Width = 5.5
Area of Rectangle = 41.25
Press any key to exit from output screen...
0 Comments