---
description: In this VB.Net Program Tutorial, we will learn about VB.Net Program Modules, VB.Net Class, and VB.Net Structure with Program &amp; Code Examples.
title: VB.Net Program with Code Examples
image: https://www.guru99.com/images/vb-net-code-examples.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

VB.Net program structure organizes code into namespaces, modules, classes, and a Main procedure that runs first. Understanding these building blocks, along with structures for grouping data, lets beginners write clear, well-organized console and Windows Forms applications in Visual Studio.

* 🔘 **Namespaces:** The Imports statement pulls a namespace such as System into scope so its methods are callable directly.
* ☑️ **Modules and classes:** Every program needs a module or class to hold its data, procedures, and executable logic.
* ✅ **Main procedure:** Main marks the entry point where execution begins in each VB.Net application.
* 🧪 **Structures:** A Structure packages several related values of different types into one user-defined value type.
* 🛠️ **Project types:** Visual Studio builds both Console and Windows Forms applications for VB.Net.
* 🤖 **AI assistance:** Copilot and IntelliCode in Visual Studio 2026 scaffold VB.Net modules and classes from plain-English prompts.

[ Read More ](javascript:void%280%29;) 

![VB.Net Program Structure](https://www.guru99.com/images/vb-net-code-examples.png) 

## Modules in VB.Net

A VB.Net program consists of the following modules:

* Namespace declaration
* One or more procedures
* A class or module
* Variables
* The Main procedure
* Comments
* Statements & Expressions

## Hello World Program Example in VB.Net

Below is a simple Hello World program example in VB.Net:

**Step 1)** Create a new console application.

**Step 2)** Add the following code:

Imports System
Module Module1

    'Prints Hello Guru99 
    Sub Main()

        Console.WriteLine("Hello Guru99")
        Console.ReadKey()

    End Sub
End Module

**Step 3)** Click the Start button from the toolbar to run it. It should print the following on the console:

[](https://www.guru99.com/images/1/052919%5F0432%5FVBNetProgra1.png)

Let us discuss the various parts of the above program:

[](https://www.guru99.com/images/1/052919%5F0432%5FVBNetProgra2.png)

**Explanation of Code:**

1. This is called the namespace declaration. What we are doing is that we are including a namespace with the name System into our programming structure. After that, we will be able to access all the methods that have been defined in that namespace without getting an error.
2. This is called a module declaration. Here, we have declared a module named Module1\. VB.Net is an object-oriented language. Hence we must have a class module in every program. It is inside this module that you will be able to define the data and methods to be used by your program.
3. This is a comment. To mark it as a comment, we added a single quote (‘) to the beginning of the sentence. The VB.Net compiler will not process this part. The purpose of comments is to improve the readability of the code. Use them to explain the meaning of various statements in your code. Anyone reading through your code will find it easy to understand.
4. A VB.Net module or class can have more than one procedure. It is inside procedures where you should define your executable code. This means that the procedure will define the class behavior. A procedure can be a Function, Sub, Get, Set, AddHandler, [Operator](https://www.guru99.com/vb-net-operators.html), RemoveHandler, or RaiseEvent. In this line, we defined the Main sub-procedure. This marks the entry point in all VB.Net programs. It defines what the module will do when it is executed.
5. This is where we have specified the behavior of the primary method. The WriteLine method belongs to the Console class, and it is defined inside the System namespace. Remember this was imported into the code. This statement makes the program print the text Hello Guru99 on the console when executed.
6. This line will prevent the screen from closing or exiting soon after the program has been executed. The screen will pause and wait for the user to perform an action to close it.
7. Closing the main sub-procedure.
8. Ending the module.

With the Hello World program in place, the next core building block of a VB.Net program is the class.

## Class in VB.Net

In VB.Net, we use classes to define a blueprint for a [Data Type](https://www.guru99.com/vb-net-data-types.html). It does not mean that a class definition is a data definition, but it describes what an object of that class will be made of and the operations that we can perform on such an object.

An object is an instance of a class. The class members are the methods and variables defined within the class.

To define a class, we use the Class keyword, which should be followed by the name of the class, the class body, and the End Class statement. This is described in the following syntax:

[ <attributelist> ] [ accessmodifier ] _
Class name 
   [ Inherits classname ]
   [ statements ]
End Class

**Here,**

* The attributeList denotes a list of attributes that are to be applied to the class.
* The accessModifier is the access level of the defined class. It is an optional parameter and can take values like Public, Protected, Protected Friend, Friend, and Private.
* The Inherits denotes any parent class that it inherits.

### VB.Net Class Example

Following is an example code to create a class in VB.Net:

**Step 1)** Create a new console application.

**Step 2)** Add the following code:

Imports System
Module Module1

    Class Figure
        Public length As Double

        Public breadth As Double
    End Class
    Sub Main()
        Dim Rectangle As Figure = New Figure()
        Dim area As Double = 0.0

        Rectangle.length = 8.0

        Rectangle.breadth = 7.0
        area = Rectangle.length * Rectangle.breadth
        Console.WriteLine("Area of Rectangle is : {0}", area)

        Console.ReadKey()
    End Sub
End Module

**Step 3)** Run the code by clicking the Start button from the toolbar. You should get the following window:

[](https://www.guru99.com/images/1/052919%5F0432%5FVBNetProgra3.png)

We have used the following code:

[](https://www.guru99.com/images/1/052919%5F0432%5FVBNetProgra4.png)

**Explanation of Code:**

1. Creating a module named Module1.
2. Creating a class named Figure.
3. Creating a class member named length of type Double. Its access level has been set to public meaning that it will be accessed publicly.
4. Creating a class member named breadth of type Double. Its access level has been set to public meaning that it will be accessed publicly.
5. Ending the class.
6. Creating the main sub-procedure.
7. Creating an object named Rectangle. This object will be of type figure, meaning that it will be capable of accessing all the members defined inside the Figure class.
8. Defining a variable named area of type Double and initializing its value to 0.0.
9. Accessing the length property defined in the Figure class and initializing its value to 8.0.
10. Accessing the breadth property defined in the Figure class and initialize its value to 7.0.
11. Calculating the area of the rectangle by multiplying the values of length and breadth. The result of this calculation will be assigned to the area variable.
12. Printing some text and the area of the rectangle on the console.
13. Pausing the console waiting for a user to take action to close it.
14. Ending the sub-procedure.
15. Ending the class.

Alongside classes, VB.Net offers structures as a lightweight way to package related values together.

### RELATED ARTICLES

* [VB.Net TEXTBOX Control Tutorial: Properties with Example ](https://www.guru99.com/vb-net-textbox.html "VB.Net TEXTBOX Control Tutorial: Properties with Example")
* [VB.Net Data Types and Variable Declaration with DIM ](https://www.guru99.com/vb-net-data-types.html "VB.Net Data Types and Variable Declaration with DIM")
* [VB.Net Operators: Types with Example ](https://www.guru99.com/vb-net-operators.html "VB.Net Operators: Types with Example")
* [VB.Net Arrays: String, Dynamic with EXAMPLES ](https://www.guru99.com/vb-net-array-string.html "VB.Net Arrays: String, Dynamic with EXAMPLES")

## Structure in VB.Net

A structure is a user-defined data type. Structures provide us with a way of packaging data of different types together. A structure is declared using the structure keyword.

### VB.Net Structure Example

Here is an example to create a structure in VB.Net:

**Step 1)** Create a new console application.

**Step 2)** Add the following code:

Module Module1
    Structure Struct
        Public x As Integer
        Public y As Integer
    End Structure
    Sub Main()
        Dim st As New Struct
        st.x = 10
        st.y = 20
        Dim sum As Integer = st.x + st.y
        Console.WriteLine("The result is {0}", sum)
        Console.ReadKey()

    End Sub 
End Module

**Step 3)** Run the code by clicking the Start button from the toolbar. You should get the following window:

[](https://www.guru99.com/images/1/052919%5F0432%5FVBNetProgra5.png)

We have used the following code:

[](https://www.guru99.com/images/1/052919%5F0432%5FVBNetProgra6.png)

**Explanation of Code:**

1. Creating a module named Module1.
2. Creating a structure named Struct.
3. Creating a variable x of type Integer. Its access level has been set to Public to make it publicly accessible.
4. Creating a variable y of type Integer. Its access level has been set to Public to make it publicly accessible.
5. End of the structure.
6. Creating the main sub-procedure.
7. Creating an object named st of type Struct. This means that it will be capable of accessing all the properties defined within the structure named Struct.
8. Accessing the variable x defined within the structure Struct and initializing its value to 10.
9. Accessing the variable y defined within the structure Struct and initializing its value to 20.
10. Defining the variable sum and initializing its value to the sum of the values of the above two variables.
11. Printing some text and the result of the above operation on the console.
12. Pausing the console window waiting for a user to take action to close it.
13. End of the main sub-procedure.
14. End of the module.

### RELATED ARTICLES

* [VB.Net TEXTBOX Control Tutorial: Properties with Example ](https://www.guru99.com/vb-net-textbox.html "VB.Net TEXTBOX Control Tutorial: Properties with Example")
* [VB.Net Data Types and Variable Declaration with DIM ](https://www.guru99.com/vb-net-data-types.html "VB.Net Data Types and Variable Declaration with DIM")
* [VB.Net Operators: Types with Example ](https://www.guru99.com/vb-net-operators.html "VB.Net Operators: Types with Example")
* [VB.Net Arrays: String, Dynamic with EXAMPLES ](https://www.guru99.com/vb-net-array-string.html "VB.Net Arrays: String, Dynamic with EXAMPLES")

## How to Create a New Project in Microsoft Visual Studio

IDE stands for Integrated Development Environment. It is where we write our code. Microsoft Visual Studio forms the most common type of IDE for VB.Net programming.

To install Visual Studio use this [guide](https://www.guru99.com/download-install-visual-studio.html).

To write your code, you need to create a new project.

Following are the steps to create a new project in Visual Studio:

**Step 1) Go to File Menu in Visual Studio**

Open Visual Studio, click on the File menu, and choose New->Project from the toolbar

[](https://www.guru99.com/images/1/052919%5F0432%5FVBNetProgra7.png)

**Step 2) Select Windows Forms Application**

On the new window, click Visual Basic from the left vertical navigation pane, and Choose Windows Forms Application.

[](https://www.guru99.com/images/1/052919%5F0432%5FVBNetProgra8.png)

**Step 3) Give a name to your project**

Give it a name and click the OK button. The project will be created.

You will have created a Windows Forms Application project. This type of project will allow you to create a graphical user interface by dragging and dropping elements.

## How to Create a Console Application Project in Visual Studio

You may need to create an application that runs on the console. This requires you to create a Console Application project. The following steps can help you achieve this:

**Step 1)** Open Visual Studio, and click the File menu, Choose New then Project from the toolbar.

[](https://www.guru99.com/images/1/052919%5F0432%5FVBNetProgra9.png)

**Step 2)** On the new window, click Visual Basic from the left vertical navigation pane. Choose Console Application.

[](https://www.guru99.com/images/1/052919%5F0432%5FVBNetProgra10.png)

**Step 3)** Give it a name and click the OK button. The project will be created.

## FAQs

🧩 What is the difference between a module and a class in VB.Net?

A module has one Shared, non-inheritable instance, so it suits helper code and console entry points. A class is a blueprint you instantiate as objects and can inherit for reusable, object-oriented designs.

🚪 What is the entry point of a VB.Net program?

The Main procedure is the entry point of every VB.Net program; the .NET runtime calls it after loading the app. Inside a module Main needs no Shared keyword, but inside a class it must be Shared.

🗂️ What is a namespace in VB.Net and why use Imports?

A namespace is the top-level container that groups related classes and modules and prevents naming conflicts. The Imports statement brings it into scope, so you can call members like Console.WriteLine directly.

🔻 When should you use a Structure instead of a Class?

Use a Structure for small, short-lived data because it is a [value type](https://www.guru99.com/vb-net-data-types.html) copied on assignment. Choose a Class for larger objects needing inheritance, references, or shared state, as classes are heap-managed reference types.

💬 Why must every VB.Net program include a module or class?

VB.Net is object-oriented, so all executable code must sit inside a module or class. This container holds the variables, procedures, and Main entry point the compiler needs to organize the program.

🤖 Can GitHub Copilot generate VB.Net program structures?

Yes. GitHub Copilot in Visual Studio 2026 can generate complete VB.Net structures, turning a plain-English comment into a Module, Class, or Main procedure. Always review the generated code before using it.

🧠 Does Visual Studio 2026 use AI to help write VB.Net code?

Yes. [Visual Studio](https://www.guru99.com/download-install-visual-studio.html) 2026 uses AI through GitHub Copilot and IntelliCode to speed up VB.Net coding, offering context-aware completions that learn your patterns and surface the most relevant members first.

🆚 What is the difference between a Console and a Windows Forms application?

A Console Application runs in a text-only command window and is ideal for learning core VB.Net syntax. A Windows Forms Application adds a graphical interface built by dragging and dropping controls for desktop apps.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/vb-net-code-examples.png","url":"https://www.guru99.com/images/vb-net-code-examples.png","width":"700","height":"250","caption":"VB.Net Code Examples","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/vb-net-program-structure.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/vb-net","name":"VB.NET"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/vb-net-program-structure.html","name":"VB.Net Program with Code Examples"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/vb-net-program-structure.html#webpage","url":"https://www.guru99.com/vb-net-program-structure.html","name":"VB.Net Program with Code Examples","dateModified":"2026-07-02T17:03:32+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/vb-net-code-examples.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/vb-net-program-structure.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/kael","name":"Kael Flynn","description":"I am Kael Flynn, a Sr. VB.NET Developer, dedicated to delivering expert guidance on mastering VB.NET development with clear, practical tutorials.","url":"https://www.guru99.com/author/kael","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/kael-flynn-author.png","url":"https://www.guru99.com/images/kael-flynn-author.png","caption":"Kael Flynn","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"VB.NET","headline":"VB.Net Program with Code Examples","description":"In this VB.Net Program Tutorial, we will learn about VB.Net Program Modules, VB.Net Class, and VB.Net Structure with Program &amp; Code Examples.","keywords":"vb-net, programming","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/kael","name":"Kael Flynn"},"dateModified":"2026-07-02T17:03:32+05:30","image":{"@id":"https://www.guru99.com/images/vb-net-code-examples.png"},"copyrightYear":"2026","name":"VB.Net Program with Code Examples","subjectOf":[{"@type":"HowTo","name":"How to Create a New Project in Microsoft Visual Studio","description":"Following are the steps to create a new project in Visual Studio:","step":[{"@type":"HowToStep","name":"Step 1) Go to File Menu in Visual Studio","text":"Open Visual Studio, click on the File menu, and https://www.guru99.com/vb-net-program-structure.html New-&gt;Project from the toolbar","image":"https://cdn.guru99.com/images/1/052919_0432_VBNetProgra7.png","url":"https://www.guru99.com/sql-server-database-create-alter-drop-restore.html#step1"},{"@type":"HowToStep","name":"Step 2) Select Windows Forms Application","text":"On the new window, click Visual Basic from the left vertical navigation pane, and https://www.guru99.com/vb-net-program-structure.html Windows Forms Application.","image":"https://cdn.guru99.com/images/1/052919_0432_VBNetProgra8.png","url":"https://www.guru99.com/sql-server-database-create-alter-drop-restore.html#step1"},{"@type":"HowToStep","name":"Step 3) Give a name to your project","text":"Give it a name and click the OK button. The project will be created.","url":"https://www.guru99.com/sql-server-database-create-alter-drop-restore.html#step2"}]},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the difference between a module and a class in VB.Net?","acceptedAnswer":{"@type":"Answer","text":"A module has one Shared, non-inheritable instance, so it suits helper code and console entry points. A class is a blueprint you instantiate as objects and can inherit for reusable, object-oriented designs."}},{"@type":"Question","name":"What is the entry point of a VB.Net program?","acceptedAnswer":{"@type":"Answer","text":"The Main procedure is the entry point of every VB.Net program; the .NET runtime calls it after loading the app. Inside a module Main needs no Shared keyword, but inside a class it must be Shared."}},{"@type":"Question","name":"What is a namespace in VB.Net and why use Imports?","acceptedAnswer":{"@type":"Answer","text":"A namespace is the top-level container that groups related classes and modules and prevents naming conflicts. The Imports statement brings it into scope, so you can call members like Console.WriteLine directly."}},{"@type":"Question","name":"When should you use a Structure instead of a Class?","acceptedAnswer":{"@type":"Answer","text":"Use a Structure for small, short-lived data because it is a value type copied on assignment. Choose a Class for larger objects needing inheritance, references, or shared state, as classes are heap-managed reference types."}},{"@type":"Question","name":"Why must every VB.Net program include a module or class?","acceptedAnswer":{"@type":"Answer","text":"VB.Net is object-oriented, so all executable code must sit inside a module or class. This container holds the variables, procedures, and Main entry point the compiler needs to organize the program."}},{"@type":"Question","name":"Can GitHub Copilot generate VB.Net program structures?","acceptedAnswer":{"@type":"Answer","text":"Yes. GitHub Copilot in Visual Studio 2026 can generate complete VB.Net structures, turning a plain-English comment into a Module, Class, or Main procedure. Always review the generated code before using it."}},{"@type":"Question","name":"Does Visual Studio 2026 use AI to help write VB.Net code?","acceptedAnswer":{"@type":"Answer","text":"Yes. Visual Studio 2026 uses AI through GitHub Copilot and IntelliCode to speed up VB.Net coding, offering context-aware completions that learn your patterns and surface the most relevant members first."}},{"@type":"Question","name":"What is the difference between a Console and a Windows Forms application?","acceptedAnswer":{"@type":"Answer","text":"A Console Application runs in a text-only command window and is ideal for learning core VB.Net syntax. A Windows Forms Application adds a graphical interface built by dragging and dropping controls for desktop apps."}}]}],"@id":"https://www.guru99.com/vb-net-program-structure.html#schema-50104","isPartOf":{"@id":"https://www.guru99.com/vb-net-program-structure.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/vb-net-program-structure.html#webpage"}}]}
```
