Following are the vb.net program structure and we will also see structure in vb.net with example with basic examples:
- How To Use Module
- How To Use Classes
- Hello Word Program
- How To Define Structure
- What is Microsoft Visual Studio IDE
What Is Module:
Table of Contents
A Module is a custom functions it is not a class it is use for container.A Module is mainly use toorganize code in a global on single place. In VB.Net By default the Sub Main is place in a Module called “Module1”.
In a project a Module is use to manage custom property of any element you will set the property in Module without property windows and it will be call any where in the project.
A VB.NET Project Consist The Following
- Namespace Declaration
- One or More Procedure
- A Class Or Module
- One Or More Variables
- The Main Procedure
- Comments
- Statement & Expression
Create a program “Hello Word” program with new project vb.net console application. Here we see the basic console application in vb.net program example.
Step 01: Open Visual Studio click on file menu , choose new and then click project. Like following pics.
Step 02 : On the new window select the visual basic language from the combo box selector in the left side.
Step 3 : Then choose the first option Console App (.Net Core) click next.
Step 04 : Enter t he name of your project in the first text box then click on create button.
Step 05 : The following main screen of Visual Studio 2019 will open. In the latest version of Visual Studio 2019 the namespace automatically declared on the top and also “hello word !” message box automatically declared.
Imports System
Module Module1
Sub Main()
Console.Write(“Hello Word !”)
Console.ReadKey()
End Sub
End Module
Step 06: Copy the above code and past in the sub main and click on the run button in the toolbar . After the successful build the following output will open with hello word with no error.
App Out Put || VB.Net Program Structure
Now we describe the above console app program on by one with the following pics.
Explain the above code || VB.Net Program Structure
- Import System: This is called the namespace declaration. What we are doing that including in namespace with the name system info our console app. After declared the namespace now we will able to access the system method . And access any module function and class in the project.
- Module Declaration: This is called module declaration .Here we declare a module with the fname of Module Program. VB.Net is a object oriented programming language we must have a class module in a program so you will be able to define the data in module.
- Comments : This is a comments before drop a comments use single quote (‘) in your line it means vb.net compiler will not execute this line.
- Procedure: Procedure are use to define a class, module, events, addhandler, Get, Set, RemoveHandler, And RaisEvents. In this section you define the main sub. Procedure will define the class behavour.
- Code : This line is use to define the code with different quires and statements. Use this to define what use input in your program in the console.
- This allow to the user to exit the program by pressing any key from the keyboard.
- End Sub (): It is use to close the sub main procedure.
- End Module: This line indicate the end of module.
Imports System
Module Program
Class product
Public price As Double
Public qty As Double
End Class
Sub Main()
Dim tot_amount As product = New product()
Dim total As Double = 0.0
tot_amount.price = 525.6
tot_amount.qty = 2
total = tot_amount.price * tot_amount.qty
Console.WriteLine(“The total amount is : {0}”, total)
Console.ReadKey()
End Sub
End Module
Accepting Values From The User || VB.Net Program Structure
In VB.Net console class or module provide function ReadLine() for accepting input from the user according to given instruction define in case of variables. And these values are stored in variables . For example:
Imports System
Module Module1
Sub Main()
Dim message As String
Console.Write(“Enter your name: “)
message = Console.ReadLine
Console.WriteLine()
Console.WriteLine(“Your Name: {0}”, message)
Console.ReadLine()
End Sub
End Module
In VB.Net program structure this function ask the use to input some text which define in variables it may be string, integer, decimal, double, date, currency etc. The user input the some text according to the function and these values will automatically stored in shape variables.The output screen will appear like this:-
vb.net program structure:
- In the above screen out the user enter the their name
- The 2nd line show the out put result which is string value in declare in variable.
Pingback: How To Load Data In Combobox From Database In Vb.net 2019? | GSS TECHNOLOGY