You are on page 1of 18

MODULE INTRO TO VB.

NET PROGRAMMING– TVPROG1

CHAPTER 2: INTRODUCTION TO VB.NET PART 2

Objectives:
a.) Identify the keywords used in VB.Net Programming.
b.) Discover how to download and install the VB.net on your
local computer.
c.) Create a simple program using the console.

Lesson 1: How to Download and Install Visual Studio

In this topic, we will learn about the introduction of Visual Studio, version, and how to
download and install Visual Studio for VB.NET.

Visual Studio is the Integrated Development Environment (IDE) provided by Microsoft in which
developers can write and execute their program to develop various types of applications such
as Windows, Web-based, console-based, Windows forms, and mobile application easily. It has a
rich collection of tools that are used to write and modify the programs and also help to detect
and correct the errors in your programs. It is not a language-specific IDE, it means Visual Studio
is not only for VB.NET language, but you can use this to write code in C#, visual basic, C++,
Python, JavaScript and many more languages supported by Visual Studio. It supports 36
different languages that are used to develop an application. It has a built-in compiler to run the
application, and it is also available for Windows and Mac OS.

Versions of Visual Studio

o Visual Studio launched First version 5.0 in 1997 and gave it name Visual Studio 97.
o Visual Studio version number 6.0 was launched in 1998 which pronounce as Visual
Studio 6.0
o Visual Studio.NET was released in 2002 with version number 7.0. o
Visual Studio.NET was released in 2003 with version number 7.1. o
Visual Studio 2005 was released in 2005 with version number 8.0. o
Visual Studio 2008 was released in 2007 with version number 9.0. o
Visual Studio 2010 was released in 2010 with version number 10.0. o
Visual Studio 2012 was released in 2012 with version number 11.0. o
Visual Studio 2013 was released in 2013 with version number 12.0. o
Visual Studio 2015 was released in 2015 with version number 14.0. o
Visual Studio 2017 was released in 2017 with version number 15.0. o
Visual Studio 2019 was released in 2019 with version number 16.0.

Page | 1
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

How to Download and Install Visual Studio for VB.NET?

Now we will follow the procedure to download Visual Studio IDE, so we can simply develop
program in VB.NET.
Step 1. For downloading the Visual Studio IDE, go through the link given below:
https://www.visualstudio.com/downloads

Select one to download IDE


o Visual Studio 2019 Community Edition
o Visual Studio 2019 Professional Edition (90 Day Free Trial)

o And Visual Studio 2019 Enterprise Edition (90 Day Free Trial) In
this tutorial, we will use Visual Studio 2019 Professional Edition

Step 2. As clicked on download link, it starts downloading an .exe file, as shown in the image
below.

Page | 2
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

Step 3. Click on the .exe file and then, it shows a pop-up window.

Step 4. Click on the Run button, and then it shows the below image.

Step 5. Click on the Continue Button

Step 6. After clicking on Continue, Visual Studio will start downloading its initial files as shown
in the image below.

Page | 3
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

Step 7. It shows the screen below, in which you have to click on the install button as shown.

Step 8. After clicking on install button, your Visual Studio IDE will start downloading and then it
displays the screen, as we have shown below.

Step 9. From the above image, select .NET desktop development and click on install open which
may take some time to download the Visual Studio in your system, as shown in below image.

Page | 4
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

Step 10. After successfully downloading and installing the Visual Studio' supportive file, it shows
the below screen in your system.

Step 11. Click on Launch button, and then it shows the below image in your screen that
represents Visual Studio has been successfully launched in your machine.

And then it shows a below screen to select the Visual Studio theme. By default, it takes Blue
theme, and if you want to change, you can easily change the Visual Studio theme by clicking on
other themes.

Page | 5
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

Step 12. After selecting the Theme, click on Start Visual Studio and then it shows a below
image in your system screen for creating a new project.

Step 13. After click on Create a new project, it shows the below screen to choose what type of
application you are going to build in Visual studio. In this you can select the Console based
application or Window Form Based application, as shown in below image. Here we chose the
Console based application, and then click on the Next button.

Step 14. When you click the Next button, it shows the below image to define the project name,
and also reminds if you want to place the solution and project in the same directory.

Page | 6
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

Step 15. And finally, your new project will be successfully created.

For more knowledge about installing Visual Studio Express, please check the link
provided;
https://www.youtube.com/watch?v=FM5AjudKHoE&list=PLC601DEA22187BBF1&index=2

Lesson 2: VB.NET Hello World Program

In the previous topic, we have installed Visual Studio 2019 and created a console-based project
with the name MYConsoleApp1. Now in this project, we will create our Hello world VB.NET
program.

A VB.NET define the following structure to create a program:


o Namespace declaration
o Procedure can be multiple
o Define a class or module
o Variables

o The Main procedure


o Statement and Expression
o Comments
Create a Hello_Program.vb file in MYConsoleApp1 project and write the following code:

Page | 7
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

Hello_Program.vb
1. Imports System 'System is a Namespace
2. Module Hello_Program
3.
4. Sub Main()
5.
6. Console.WriteLine("Hello, Welcome to the world of VB.NET")
7. Console.WriteLine("Press any key to continue...")
8. Console.ReadKey()
9.
10. End Sub
11.
12. End Module
Let's compile and run the above program by pressing the F5 key, we get the follwoiing output.
Output:

An Alternate method to compile and execute the VB.NET program

We can also compile and execute the VB.NET program using the Command prompt instead of
using the Visual Studio IDE.

Step 1: After creating and saving the Hello_Program.vb file in the MYConsoleApp1 project,
open the command prompt and execute the commands, as we have shown in the prompt.
In place of MYConsoleApp1you can write your project name.

Page | 8
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

Step 2: After that, write vbc Hello_Program.vb, as shown below.

Step 3: If there is no error found at compile-time, it transfers the control in the next line for
generating the Hello_Pogram.exe file.
Step 4: Type Hello_Program to run the program. We get the following output.
Output:

Hello, Welcome to the world of VB.NET.


Now we will understand the basic structure of the VB.NET program:

o In VB.NET programming, the first line of the program is "Import System", where Imports
is a statement that inherit the system namespace. A System is a namespace that
contains basic classes, reference data types, events, attributes, and various inbuilt
functions that help to run the program.

o The Second line defines the Module It specifies the VB.NET filename. As we know,
VB.NET language is a completely object-oriented language, so every program must
contain a module or class in which you can write your program that contains data and
procedures within the module.

1. Module Module1
2. End Module

o You can define more than one procedure in classes and modules. Generally, the
procedure contains executable code to run. A procedure may contain the following
function:
o Function
o Operator
o Sub

o Get
o Set

Page | 9
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

o AddHandler
o RemoveHandler

o Every program must contain a Main() method. In VB.NET, there is a Main() method or
procedure that represents the starting point to execute a program, as we have seen in C
language, their entry point is the main() function.

o A comment (') symbol is used to comment on a line that is ignored by the compiler in a
program, and it is a good practice to use comments for a better understanding of the
program.

o The Console.WriteLine() is a method of the console class. It is used to print any text or
messages in the application. And the Console.ReadKey() is used to read a single
character from the keyboard back to the Visual Studio IDE.

Create a VB.NET program using Windows Form


If you want to create a new Window-based project in Visual Studio, follow the steps given below:

Step 1. Start the Visual Studio IDE.


Step 2. To create a project, click on File -> choose-> New-> Project

The following window appears on the screen.


Step 3: Select Windows Forms App (.NET Framework) and click on the Next button.

Page | 10
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

Step 4: Provide the Project name and location to store the project file using the browse button
in Location.

Step 5: Click on the Create button. The following window appears on the screen.

Page | 11
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

Step 6: Now double click on the middle area of Form1.vb (Design) file, it shows the following
code.

Form1.vb
1. Public Class Form1

2. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


3. MsgBox("Welcome to the JavaTpoint")
4. End Sub
5. End Class
Step7: Save file as Form1.vb.

Step 8: To compile and run the Form1.vb file, press F5 button or Start button in Visual Studio. It
shows the following output.

For more knowledge about console commands, please check the link provided;
https://www.youtube.com/watch?v=odjI1FMN2Ec&list=PLsJBMeqEdtggJi2khGAjgnQ

Page | 12
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

Lesson 3: VB.NET Keywords

A keyword is a reserved word with special meanings in the compiler, whose meaning
cannot be changed. Therefore, these keywords cannot be used as an identifier in VB.NET
programming such as class name, variable, function, module, etc.

In this section, we will understand about the VB.NET identifier, VB.NET comment, and how we
can use it in VB.NET.
There are following reserved keyword available in the VB.NET language.

AddHandler AddressOf Alias And AndAlso As

Boolean ByRef Byte ByVal Call Case

Catch CBool CByte CChar CDate CDbl

CDec Char Cint Class CLng CObj

Const Continue CSByte CShort CSng CStr

CType CUnit CULng CUShort Date Decimal

Declare Default Delegate Dim DirectCast Do

Double Each Else Elseif End End if

Enum Erase Error Event Exit False

Finally For Friend Function Get GetType

GetXML Global GoTO Handles If Implements


Namespace

Imports In Inherits Integer Interface Is

isNot Let Lib Like Long Loop

Me Mod Module MustInherit MustOverride MyBase

MyClass Namespace Narrowing New Next Not

Nothing Not Not Object Of On


Inheritable Overridable

Page | 13
MODULE INTRO TO VB.NET PROGRAMMING– CPPROG1

Operator Option Optional Or OrElse Overloads

Overridable Overrides ParamArray Partial Private Property

Protected Public RaiseEvent ReadOnly ReDim REM

Remove Handler Resume Return SByte Select Set

Shadows Shared Short Single Static Step

Stop String Structure Sub SyncLock Then

Throw To True Try TryCast TypeOf

UInteger While Widening With WithEvents WhiteOnly

Xor #Else IsReference TimeOfDay Append Auto


Let's create a program to find the area and perimeter of a rectangle in VB.NET.
Rectangle.vb
1. Module Rectangle

2. Public Length As Integer

3.
4. Public Breadth As Integer
5. Public Sub Dimension()
6. Length = 5

7. Breadth = 6
8. End Sub
9. Public Function Area() As Integer
10. Area = Length * Breadth
11. End Function

12. Public Function Pera() As Integer


13. Pera = 2 * (Length + Breadth)
14. End Function

Page | 14
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

15. Public Sub Display()


16. Console.WriteLine(" Length is: {0}", Length)
17. Console.WriteLine("Breadth is: {0}", Breadth)

18. Console.WriteLine(" Area of Rectangle is: {0}", Area())


19. Console.WriteLine(" Perimeter of Rectangle is: {0}", Pera())
20. End Sub
21. Sub Main()
22. Dimension() ' directly call the function in main method

23. Area()
24. Pera() ' directly call the function in main method
25. Display()
26. Console.WriteLine("Press any key to exit...")
27. Console.ReadKey()

28. End Sub


29. End Module
Output:
Length is: 5
Breadth is: 6

Area of Rectangle is: 30


Perimeter of Rectangle is: 22
Press any key to exit...
VB.NET Identifiers

As the name defines, an identifier is used to identify the name of variable, function, class, or
any other user-defined elements in the program. An identifier should be the combination of
letter, digit, and underscore. Still, the first character of the identifier or variable name should
start with alphabet letter or underscore (_) of any length.

Page | 15
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

There are various rules for identifier in VB.NET, as follows:

1. The first character of an identifier must start with an alphabet or underscore, that could
be followed by any sequence of digits (0-9), letter or underscore.
2. An identifier should not contain any reserved keyword.
3. It should not start with any digit.
4. It should not more than 51 characters.
5. An identifier can contain two underscores, but should not be consecutive.
6. It should not include any commas or white spaces in-between characters.

Generally, identifiers are meaningful names. Some valid identifiers are:


Value, a, rec1, my_data, Marks, num, etc.
Some invalid identifiers are:
5be : First character should be alphabets or underscore (_)
Class, Shared : Keyword are not allowed as identifier name.
A# - : Identifier does not contain any special symbol.
Avg marks : It should not contain any blank space.
Program.vb
1. Imports System
2. Module Program ' Identifier' name should be valid
3.
4. Public Sub myfunc() ' function name
5. Console.WriteLine("Hello friends..")
6. End Sub
7.
8. Sub Main()
9. myfunc()
10. Console.WriteLine("Nice to meet you...")
11. Console.WriteLine("press any key to exit...")
12. Console.ReadKey()
13. End Sub
14. End Module
Let's compile and execute the above program.
Output:
Hello friends...
Nice to meet you...
press any key to exit...

Page | 16
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

VB.NET Comments

A comment is used to explain the various steps that we have taken in our programming. The
compiler ignores these comment statements because the compiler is not executed or
processed in VB.NET. Therefore, it does not take any place in your compilation code.
In VB.NET, we use ( ' ) symbol to comment a statement.
1. Sub main()
2. 'Here Console.WriteLine() is used to print a statement.
3. Console.WriteLine(" Welcome to JavaTpoint")
4. 'Above statement displays Welcome to JavaTpoint
5. End Sub
Circle.vb
1. Imports System
2. Public Class Circle
3. 'define the variable
4. Dim radius As Integer = 10
5. Public Function SetCircle() As Double
6. SetCircle = 2 * 3.14 * radius ' Function is used to return some value
7. End Function
8. Public Sub display() ' create display() sub function to print the message
9. Console.Write(" Radius is: {0}", radius)
10. Console.WriteLine(" Circumference of Circle: {0}", SetCircle())
11. End Sub
12. 'Shared keyword can be used without creating an object
13. Shared Sub Main()
14. Dim obj As New Circle()
15. obj.SetCircle() 'object reference
16. obj.display()
17. Console.ReadKey()
18. End Sub
19. End Class

Now compile and execute the above program.


Output:
Radius is: 10 Circumference of Circle: 62.8
press any key to exit...
Hence, it is the best way to explain every step of VB.NET programming language.

Page | 17
MODULE INTRO TO VB.NET PROGRAMMING– TVPROG1

For more knowledge about comments, please check the link provided;
https://www.youtube.com/watch?v=pojrX2CrNCw&list=PLC601DEA22187BBF1&inde
x=6

REFERENCES

https://www.javatpoint.com/vb-net-download-and-install-visual-studio
https://www.javatpoint.com/vb-net-hello-world-program
https://www.javatpoint.com/vb-net-keywords

Page | 18

You might also like