Visual Basic Hallo World
Visual Basic Hallo World
Using Visual Studio, we can easily create a Hello World Program or Console Application in
Visual Basic based on our requirements.
In the previous chapter, we learned how to Download and Install Visual Studio on Windows
Machine. In case if you don't install a visual studio, then follow the instructions to install a visual
studio otherwise open your visual studio.
Once you click on Project, a new popup will open in that select Visual Basic from the left pane
and choose Console App. In the Name section, give any name for your project, select the
appropriate Location path to save your project files, and click OK like as shown below.
Once we click on OK button, a new console application will be created like as shown below. If
the Module1.vb file is not opened in your code editor, open the Solution Explorer menu on the
right side and double click on your Module1.vb file.
If you observe the above image, by default, the application contains a Main() method because
the console applications in visual basic will always start from the Main() method of program
class.
Imports System
Module Module1
Sub Main()
Console.WriteLine("Hello World!")
Console.WriteLine("Press Enter Key to Exit.")
Console.ReadLine()
End Sub
End Module
If you observe the above code, we used many parameters to implement the “Hello World”
program in visual basic. In the next section, we will learn all the parameters in detail.
Imports System;
Here, Imports System is the .NET Framework library namespaces and we used Imports
keyword to import system namespace to use existing class methods such WriteLine(),
ReadLine(), etc. By default, the .NET Framework provides a lot of namespaces to make the
application implementation easy.
The namespace is a collection of classes, and classes are the collection of objects and methods.
Module Module1
Here, Module Module1 is used to define a module (Module1). The module (Module1) will
contain all the variables, methods, etc., based on our requirements.
Sub Main()
Console.WriteLine() / ReadLine()
Here, Console.WriteLine() and Console.ReadLine() methods are used to write a text to the
console and read the input from the console.
The Console is a class of .NET Framework namespace System and WriteLine() and ReadLine()
are the methods of Console class.
Once we click on the Start option or Ctrl + F5, our program will compile and show the result
below.
This is how we can create and execute the applications in visual basic (vb) programming
language using visual studio based on our requirements.