ARTICLE

Class in VB.NET

Posted by Manish Tewatia Articles | General June 24, 2010
A class defines a collection of encapsulated instance variables, methods, functions, optionally including implementations of those types and a constructor and destructor.
 
Reader Level:


What is a Class

A class defines a collection of encapsulated instance variables and methods, functions, optionally including implementations of those types and a constructor and destructor.

In this article, we will see how to use Visual Studio to add and work with classes using VB.NET.

Steps

For adding a new class to a project, you have to follow this steps:-

You can add class by two ways, "directly go to the project menu and select Add New Item or Go the solution explorer Right click on project and chose Add New Item option", in Your Opened Project.
Untitled-1.gif

Figure 1

Untitled-2.gif
Figure 2


Choose Visual Basic Class From Solution items and Click on Add button.

Untitled-3.gif

Figure 3
When you add a class to a project, Visual Basic Automatically generates the Class and End Class Statement so you can enter the code for the class between them.

Untitled-4.gif

Figure 4
As for displaying simple string in a console application like ("Welcome User"), you have to write this code between the newly added class body.

Public Class test

    Sub disp()

        Console.WriteLine("welcome user")

        Console.ReadLine()

 

    End Sub

End Class
And write this code in existing Module body .

Imports System.Console

Module Module1

    Sub Main()

        Dim obj As New test()

        obj.disp()

        Read()

 

    End Sub

 

End Module
After writing this code, build or debug the application. The output screen looks like following.

Untitled-5.gif

Figure 5
Summery

In this simple article, you can learned how to add a new class to an existing project using Visual Studio and how to call this class from a project module. 

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor