A Visual Basic program is built up from standard building blocks. A solution comprises one or more projects.
When you create a project or file, you will see that some code is available in a particular order. Any code that you write should follow the following sequence.
If you enter statements in a different order, you will get a compilation error.
A program can also contain conditional compilation statements. You can intersperse these in the source file among the statements of the preceding sequence.
Option statements establish ground rules for subsequent code, helping prevent syntax and logic errors.
Binary or Text values.You can include an Imports Statement (.NET Namespace and Type) to import names defined outside your project.
Namespace statement to classify the following statements within a particular namespace.Conditional compilation statements can appear almost anywhere in your source file.
Classes, structures, and modules contain all the code in your source file. They are namespace-level elements, which can appear within a namespace or at the source file level.
Procedures, operators, properties, and events are the only programming elements that can hold executable code (statements that perform actions at run time).
The following module-level elements of your program.
Data elements at the module level are variables, constants, enumerations, and delegates.
Most of the contents of procedure-level elements are executable statements, which constitute the run-time code of your program.
Function, Sub, Operator, Get, Set, AddHandler, RemoveHandler, RaiseEvent).The Main procedure is the first code to run when your application has been loaded. Main serves as the starting point and overall control for your application.
There are four variations of the Main
Sub Main()
Sub Main(ByVal cmdArgs() As String)
Function Main() As Integer
Function Main(ByVal cmdArgs() As String) As Integer
The most common variety of this procedure is Sub Main().
Let's have a look at a simple code that would print the string "Welcome to VB.NET Tutorial."
Imports System
Module Program
'It will display a string on the console
Sub Main(args As String())
Console.WriteLine("Welcome to VB.NET Tutorial.")
End Sub
End Module
Let's discuss various parts of the above program.
Imports System is used to include the System namespace in the program.Module declaration, the module Program.' will be ignored by the compiler because it a comment.Main procedure, which is the entry point for all VB.Net programs.Main procedure states what the module or class will do when executed.Console.WriteLine("Welcome to VB.NET Tutorial.") in the Main procedure print the string on the screen.