Category: VB.Net progrmas

Write a program to demonstrate Constructors and Destructors in VB.net.

WAP to Demonstrate Constructors and Destructors in VB.net.

 

Imports System.Console

Module Module1

Class base

Private a As Integer

Private b As Double

Private c As String

 

Public Sub New(ByVal x As Integer, ByVal y As Double, ByVal z As String)

WriteLine("Constructor Of Base Class Executed ! ")

a = x

b = y

c = z

WriteLine("a=" & a)

WriteLine("b=" & b)

WriteLine("c=" & c)

End Sub

 

Protected Overrides Sub finalize()

WriteLine("Destructor of Base Class Executed ! ")

End Sub

End Class

 

Class derive : Inherits base

Private d As Integer

Public Sub New(ByVal e As Integer, ByVal x As Integer, ByVal y As Double, ByVal z As String)

MyBase.New(x, y, z)

WriteLine("Constructor of Derived Class Executed!")

d = e

WriteLine("d=" & d)

End Sub

Protected Overrides Sub finalize()

WriteLine("Destructor of Derived Class Executed ! ")

End Sub

End Class

 

Sub Main()

WriteLine("When WE Declare Object of Base Classs :- ")

WriteLine()

WriteLine()

Dim s1 As base = New base(20, 30.5, "GOGO")

 

WriteLine("When WE Declare Object of Derived Classs :- ")

WriteLine()

WriteLine()

Dim s2 As derive = New derive(10, 20, 30.5, "GOGO")

 

End Sub

 

End Module

OUTPUT

Program to implement Constructors and Destructors in VB.net

output of vb.net Program to implement Constructors and Destructors

Read More
admin October 17, 2014 0 Comments

Program in VB.Net to build a class which implements an interface

Que : Write a program in VB.Net to build a class which implements an interface

Ans:

Imports System.Console

 

Interface inf1

Sub show()

Sub disp()

End Interface

 

Class class1 : Implements inf1

 

Public Sub disp() Implements inf1.disp

WriteLine("Disp of class 1")

End Sub

 

Public Sub show() Implements inf1.show

WriteLine("show of Class 1")

End Sub

End Class

 

 

Module Module1

Sub Main()

Dim obj As class1 = New class1()

obj.disp()

obj.show()

 

End Sub

 

End Module

OUTPUT :

 

Read More
admin October 17, 2014 0 Comments

Demonstrate Polymorphism in Vb.net through Constructor overloading.

Que : WAP to demonstrate Polymorphism in Vb.net through Constructor overloading.

 

Polymorphism in VB.NET

Polymorphism is the concept that different objects have different implementations of the same characteristic. … Given two different classes with the same properties and methods, a variable of type object could be used to instantiate an object of either class

 

Constructor overloading in vb.net

When the same method name is used for more than one method, with different types of parameters and returned types, then the method is said to be overloaded. Constructor is a special method called ‘New()’ in vb.net and is defined as a Sub.Overloading feature is used most frequently to overload the constructor. We overload the constructor by defining more than one ‘Sub New()’ procedure. By overloading a constructor, we make available more than one constructor.So, while creating an object we can choose which constructor we want to use to instantiate the object. The only condition while overloading the constructor is that the constructor should have a signature which is different from other constructors.

 

Imports System.Console

Module Module1

Structure areas

Public area As Integer

Public Sub display()

WriteLine("Area = " & area)

End Sub

Public Sub New(ByRef side As Integer)

area = side * side

End Sub

Public Sub New(ByVal l As Integer, ByVal b As Integer)

area = l * b

End Sub

Public Sub New(ByVal r As Double)

area = 4.13 * r * r

End Sub

End Structure

 

Sub Main()

Dim l, b, ch As Integer

Dim r As Double

WriteLine("1. Area of a Square")

WriteLine("2. Area of a Rectange")

WriteLine("3. Area of a Circle")

WriteLine("Enter Your Choice : ")

ch = ReadLine()

 

Select Case ch

Case 1

Write("Enter Size of a side : ")

l = ReadLine()

Dim s1 As areas = New areas(l)

s1.display()

Case 2

Write("Enter length : ")

l = ReadLine()

Write("Enter breadth : ")

b = ReadLine()

Dim s1 As areas = New areas(l, b)

s1.display()

Case 3

Write("Enter radius : ")

r = ReadLine()

Dim s1 As areas = New areas(r)

s1.display()

Case Else

WriteLine("Enter a Valid Choice")

End Select

End Sub

End Module

 

Output :

 

Read More
admin October 17, 2014 0 Comments

WAP to demonstrate Polymorphism in Vb.net through Method Overloading

 Demonstratation of  Polymorphism in Vb.net through Method Overloading :

code begins :

(more…)

Read More
admin October 17, 2014 0 Comments

Program to demonstrate abstract class and abstract methods in VB.net.

Ques :Write a program to demonstrate abstract class and abstract methods in VB.net. (more…)

Read More
admin October 17, 2014 0 Comments

VBScript Full Program for structure | Structure in VBScript

Before Writing a program for structure in VBScript we have to know what is a structure .? A structure is a generalization of the user-defined type (UDT) supported by previous versions of Visual Basic (VB). In addition to fields, structures can expose properties, methods, and events. A structure can implement one or more interfaces, and you can declare individual access levels for each field.

 

You can combine data items of different types to create a structure in VBscript. A structure link one or more elements with each other and with the structure itself. When you declare a structure in VBScript, it becomes a composite data type, and you can declare variables of that type.

Structures in VB Script are useful when you want a single variable to hold several related pieces of information. For example, you might want to keep a student’s name, telephone extension, and fee together. You could use several variables for this information, or you could define a structure and use it for a single student variable. The advantage of the structure becomes apparent when you have many students and therefore many instances of the variable.

 

Write a program for structures in VB Script

 

Here is a full VBScript Program for structure but if You Don’t Basics About Structures

we recommend you to check Basics First about Structures in VBScript  :

 

How to: Declare a Structure in VBScript
Shows how to declare a structure and its elements.

VB Script Structure Variables
Covers assigning a structure to a variable and accessing its elements.

VBScript Structures and Other Programming Elements
Summarizes how structures interact with arrays, objects, procedures, and each other.

VBScript Structures and Classes
Describes the similarities and differences between structures and classes.

 

Vbscript Program for Structure :

Imports System.Console

Module Module1

Structure student
Public rollno As Integer
Public name As String
Public Sub display()
WriteLine("The roll No. Is : " & rollno)
WriteLine("The Name is : " & name)
End Sub
Public Sub New(ByVal r As Integer, ByVal n As String)
name = n
rollno = r
End Sub
End Structure

Sub Main()
Dim x As Integer
Dim y As String
WriteLine("Enter Your Name : ")
y = ReadLine()
WriteLine("Enter Your Rollno. : ")
x = ReadLine()
Dim s1 As student = New student(x, y)
s1.display()

End Sub

End Module

 

OUTPUT of VB Script Program For Structure :

VBscript  program for structures.

Read More
admin January 18, 2014 0 Comments