Visual Basic .NET (VB.
NET)
What is VB.Net? Introduction,
History, Features, Advantages,
Disadvantages
What is VB.Net?
VB.NET stands for Visual Basic.NET, and it is a computer programming language developed by
Microsoft. It was first released in 2002 to replace Visual Basic 6. VB.NET is an object-oriented
programming language. This means that it supports the features of object-oriented programming
which include encapsulation, polymorphism, abstraction, and inheritance.
Visual Basic .ASP NET runs on the .NET framework, which means that it has full access to the
.NET libraries. It is a very productive tool for rapid creation of a wide range of Web, Windows,
office and Mobile applications that have been built on the .NET framework. The language was
designed in such a way that it is easy to understand to both novice and advanced programmers.
Since VB.NET relies on the .NET framework, programs written in the language run with much
reliability and scalability. With VB.NET, you can create applications that are fully object-
oriented, similar to the ones created in other languages like C++, Java, or C#. Programs written
in VB.NET can also interoperate well with programs written in Visual C++, Visual C#.
VB.NET treats everything as an object. It is true that VB.NET is an evolved version of Visual
Basic 6, but it's not compatible with it. If you write your code in Visual Basic 6, you cannot
compile it under VB.NET.
History of VB.NET
• VB.NET is a multi-paradigm programming language developed by Microsoft on the
.NET framework. It was launched in 2002 as a successor to the Visual Basic language.
This was the first version of VB.NET (VB.NET 7.0) and it relied on .NET version 1.0.
• In 2003, the second version of VB.NET, VB.NET 7.1, was released. This one relied on
.NET version 1.1. This version came with a number of improvements including support
for .NET Compact Framework and an improved reliability and performance of the .NET
IDE. VB.NET 2003 was also made available in the academic edition of Visual
Studio.NET and distributed to various scholars from different countries for free.
• In 2005, VB.NET 8.0 was released. The .NET core portion was dropped from its name so
as to distinguish it from the classical Visual Basic language. This version was named
Visual Basic 2005. This version came with many features since Microsoft wanted this
language to be used for rapid application developers. They also wanted to make it
different from C# language. Some of the features introduced by this version of VB.NET
Notes Complied by E. Wachira
included partial classes, generics, nullable types, operator overloading, and unsigned
integer support. This version also saw the introduction of the IsNot operator.
• In 2008, VB 9.0 was introduced. This was released together with .NET 3.5. Some of the
features added to this release of VB.NET included anonymous types, true conditional
operator, LINQ support, XML literals, Lambda expressions, extension methods, and type
inference.
• In 2010, Microsoft released VB 2010 (code 10.0). They wanted to use a Dynamic
Language Runtime for this release, but they opted for co-evolution strategy shared
between VB.NET and C# to bring these languages closer to each other.
• In 2012, VB 2012 (code 11.0) was release together with .NET 4.5. Its features included
call hierarchy, iterators, caller data, asynchronous programming with “await” and
“async” statements and the “Global” keyword in the “namespace” statements.
• In 2015, VB 2015 (code 14.0) was released alongside Visual Studio 2015. The “?.”
operator was introduced to do inline null checks. A string interpolation feature was also
introduced to help in formatting strings inline.
• In 2017, VB 2017 (code 15.0) was introduced alongside Visual Studio 2017. A better
way of organizing source code in just a single action was introduced.
VB.NET Features
VB.NET comes loaded with numerous features that have made it a popular programming
language amongst programmers worldwide.
These features include the following:
• VB.NET is not case sensitive like other languages such as C++ and Java.
• It is an object-oriented programming language. It treats everything as an object.
• Automatic code formatting, XML designer, improved object browser etc.
• Garbage collection is automated.
• Support for Boolean conditions for decision making.
• Simple multithreading, allowing your apps to deal with multiple tasks simultaneously.
• Simple generics.
• A standard library.
• Events management.
• References. You should reference an external object that is to be used in a VB.NET
application.
• Attributes, which are tags for providing additional information regarding elements that
have been defined within a program.
• Windows Forms- you can inherit your form from an already existing form.
Notes Complied by E. Wachira
The following reasons make VB.Net a widely used professional language
• Modern, general purpose.
• Object oriented.
• Component oriented.
• Easy to learn.
• Structured language.
• It produces efficient programs.
• It can be compiled on a variety of computer platforms.
• Part of .Net Framework.
Strong Programming Features VB.Net
VB.Net has numerous strong programming features that make it endearing to multitude of
programmers worldwide.
some of these features:
1. Object-Oriented Programming (OOP)
VB.NET supports full OOP principles:
• Encapsulation, Inheritance, Polymorphism
• Support for abstract classes, interfaces, overloading, and overriding
• Promotes modular, reusable code
2. Automatic Garbage Collection
• Memory management is handled by the .NET runtime
• Reduces the likelihood of memory leaks
Notes Complied by E. Wachira
3. Structured Exception Handling
• Built-in support using Try, Catch, Finally, and Throw
• Allows clean error handling and debugging
4. Strong Data Type Checking
• Type-safe language: detects type mismatches at compile time
• Reduces runtime errors and improves performance
5. Rapid Application Development (RAD)
• Tight integration with Visual Studio IDE
• Drag-and-drop GUI design with Windows Forms
• Intuitive syntax ideal for beginners
6. Language Interoperability
• Can use libraries written in C#, F#, or other .NET languages
• Common Language Runtime (CLR) enables multi-language integration
VB.Net - Environment Setup
The .Net Framework
The .Net framework is a revolutionary platform that helps you to write the following types of
applications
1. Windows Applications (Desktop Applications)
• Built using Windows Forms (WinForms) or Windows Presentation Foundation
(WPF)
• Rich graphical interfaces
• Example: Inventory management software, POS systems, desktop utilities
2. Web Applications
• Developed using ASP.NET Web Forms, ASP.NET MVC, or ASP.NET Web API
Notes Complied by E. Wachira
• Used for building dynamic websites, REST APIs, and enterprise-level web platforms
• Example: E-commerce sites, company intranets
3. Web Services
• Build and consume SOAP and RESTful services
• Enable communication between different applications/platforms
• Technologies: WCF (Windows Communication Foundation) and ASP.NET Web API
4. Console Applications
• Lightweight command-line tools or background processes
• Suitable for tasks like automation, scripts, and utilities
5. Mobile Applications (with Xamarin/.NET MAUI)
• Using extensions like Xamarin, you can build cross-platform mobile apps for Android
and iOS using .NET
• .NET MAUI is the modern evolution of Xamarin
6. Cloud Applications
• With integration to Microsoft Azure, .NET supports building scalable and reliable cloud-
based apps
• Ideal for SaaS, PaaS, and serverless functions
7. Game Development
• With tools like Unity, which uses C# (a .NET language), you can create 2D/3D games for
multiple platforms
8. IoT (Internet of Things) Applications
• Using .NET Core or .NET 5/6+, you can build applications that interact with sensors and
devices
9. Enterprise Applications
• ERP, CRM, and other large-scale business solutions using enterprise-grade technologies
like:
o ASP.NET MVC
o WCF
o Entity Framework
Notes Complied by E. Wachira
10. AI and Machine Learning Applications
• With ML.NET and integration with Python libraries, you can perform predictive
analytics, classification, etc.
The .Net framework applications are multi-platform applications. The framework has been
designed in such a way that it can be used from any of the following languages: Visual Basic,
C#, C++, Jscript, and COBOL(Common Business-Oriented Language), etc.
The .Net framework consists of an enormous library of codes used by the client languages like
VB.Net. These languages use object-oriented methodology.
Following is some of the components of the .Net framework
1. Common Language Runtime (CLR)
• The execution engine for .NET applications.
• Responsibilities:
o Memory management (Garbage Collection)
o Exception handling
o Security
o Thread management
• Converts MSIL (Microsoft Intermediate Language) into native code using the Just-In-
Time (JIT) compiler.
2. .NET Class Library (Base Class Library - BCL)
• A comprehensive collection of reusable classes, interfaces, and types.
• Provides core functionalities such as:
o File I/O
o Collections
o Data types
o String manipulation
o Networking
o XML processing
3. Common Type System (CTS)
• Defines how types are declared, used, and managed in the CLR.
Notes Complied by E. Wachira
• Ensures type safety and language interoperability.
• Example: An int in C# is the same as an Integer in VB.NET.
4. Common Language Specification (CLS)
• A set of basic rules that all .NET languages must follow.
• Promotes interoperability among different .NET languages (e.g., C#, VB.NET, F#).
5. Assemblies and Metadata
• An assembly is the compiled code (EXE or DLL) that contains metadata about the
program.
• Metadata describes:
o The types defined in the assembly
o Versioning information
o Security permissions
6. Windows Forms
• A GUI class library used to create Windows desktop applications.
• Provides drag-and-drop UI design capabilities in Visual Studio.
7. ASP.NET
• A web application framework for building dynamic websites, web APIs, and web
services.
• Includes:
o Web Forms
o MVC (Model-View-Controller)
o Web API
8. ADO.NET
• Provides classes for data access and database interaction.
• Supports SQL Server, Oracle, MySQL, and more.
9. Windows Presentation Foundation (WPF)
• A more modern UI framework than Windows Forms.
• Uses XAML (Extensible Application Markup Language) for rich user interfaces.
Notes Complied by E. Wachira
10. Windows Communication Foundation (WCF)
• Used to build service-oriented applications (SOA).
• Supports secure, reliable, and transacted messaging.
11. Windows Workflow Foundation (WF)
• Provides an API for building workflow-based applications (e.g., business process
automation).
12. Language Support
• The .NET Framework supports multiple languages:
o C#
o VB.NET
o F#
o and more
Writing VB.Net Programs on Linux or Mac OS
Although the.NET Framework runs on the Windows operating system, there are some alternative
versions that work on other operating systems. Mono is an open-source version of the .NET
Framework which includes a Visual Basic compiler and runs on several operating systems,
including various flavors of Linux and Mac OS. The most recent version is VB 2012.
The stated purpose of Mono is not only to be able to run Microsoft .NET applications cross-
platform, but also to bring better development tools to Linux developers. Mono can be run on
many operating systems including Android, BSD, iOS, Linux, OS X, Windows, Solaris and
UNIX.
Advantages of VB.NET
The following are the pros/benefits you will enjoy for coding in VB.NET:
• Your code will be formatted automatically.
• You will use object-oriented constructs to create an enterprise-class code.
• You can create web applications with modern features like performance counters, event
logs, and file system.
• You can create your web forms with much ease through the visual forms designer. You
will also enjoy drag and drop capability to replace any elements that you may need.
Notes Complied by E. Wachira
• You can connect your applications to other applications created in languages that run on
the .NET framework.
• You will enjoy features like docking, automatic control anchoring, and in-place menu
editor all good for developing web applications.
Disadvantages of VB.NET
Below are some of the drawbacks/cons associated with VB.NET:
• VB.NET cannot handle pointers directly. This is a significant disadvantage since pointers
are much necessary for programming. Any additional coding will lead to many CPU
cycles, requiring more processing time. Your application will become slow.
• VB.NET is easy to learn. This has led to a large talent pool. Hence, it may be challenging
to secure a job as a VB.NET programmer.
Summary
• VB.NET was developed by Microsoft.
• It is an object-oriented language.
• The language is not case sensitive.
• VB.NET programs run on the .NET framework.
• In VB.NET, the garbage collection process has been automated.
• The language provides windows forms from which you can inherit your own forms.
• VB.NET allows you to enjoy the drag and drop feature when creating a user interface.
VB.Net - Basic Syntax
VB.Net is an object-oriented programming language. In Object-Oriented Programming
methodology, a program consists of various objects that interact with each other by means of
actions. The actions that an object may take are called methods. Objects of the same kind are said
to have the same type or, more often, are said to be in the same class.
When we consider a VB.Net program, it can be defined as a collection of objects that
communicate via invoking each other's methods. Let us now briefly look into what do class,
object, methods and instance variables mean.
Notes Complied by E. Wachira
• Object − Objects have states and behaviors. Example: A dog has states - color, name,
breed as well as behaviors - wagging, barking, eating, etc. An object is an instance of a
class.
• Class − A class can be defined as a template/blueprint that describes the behaviors/states
that objects of its type support.
• Methods − A method is basically a behavior. A class can contain many methods. It is in
methods where the logics are written, data is manipulated and all the actions are
executed.
• Instance Variables − Each object has its unique set of instance variables. An object's
state is created by the values assigned to these instance variables.
Compile & Execute VB.Net Program
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.
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
Notes Complied by E. Wachira
Step 2) Select Windows Forms Application
On the new window, click Visual Basic from the left vertical navigation pane, and Choose
Windows Forms Application.
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 Form 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.
Notes Complied by E. Wachira
Step 2) On the new window, click Visual Basic from the left vertical navigation pane. Choose
Console Application.
Step 3) Give it a name and click the OK button. The project will be created.
Summary
• A VB.Net program is composed of various parts.
Notes Complied by E. Wachira
• After importing a namespace into a program, it becomes possible for us to use all the
methods and functions that have been defined in that module.
• Every VB.Net program must have a module.
• The VB.Net compiler ignores comments.
• We can have more than one procedures in a VB.Net program.
You can compile a VB.Net program by using the command line instead of the Visual Studio
IDE:
• Open a text editor and add your code.
• Save the file as helloworld.vb
• Open the command prompt tool and go to the directory where you saved the file.
• Type vbc helloworld.vb and press enter to compile your code.
• If there are no errors in your code the command prompt will take you to the next line and
would generate helloworld.exe executable file.
• Next, type helloworld to execute your program.
• You will be able to see "Hello World" printed on the screen.
VB.Net - Program Structure
Before we study basic building blocks of the VB.Net programming language, let us look a bare
minimum VB.Net program structure so that we can take it as a reference in upcoming chapters.
A VB.Net program basically consists of the following parts
• Namespace declaration
• A class or module
• One or more procedures
• Variables
• The Main procedure
• Statements & Expressions
• Comments
Notes Complied by E. Wachira
Let us look at a simple code that would print the words "Hello World"
When the above code is compiled and executed, it produces the following result −
Hello, World!
The various parts of the above program:
Notes Complied by E. Wachira
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 procedures. 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,,
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.
Notes Complied by E. Wachira
Class in VB.Net
When you define a class, you define a blueprint for a data type. This doesn't actually define any
data, but it does define what the class name means, that is, what an object of the class will consist
of and what operations can be performed on such an object.
Objects are instances of a class. The methods and variables that constitute a class are called
members of the class.
Class Definition
A class definition starts with the keyword Class followed by the class name; and the class body,
ended by the End Class statement. Following is the general form of a class definition
Where,
• attributelist is a list of attributes that apply to the class. Optional.
• accessmodifier defines the access levels of the class, it has values as - Public, Protected,
Friend, Protected Friend and Private. Optional.
• Shadows indicate that the variable re-declares and hides an identically named element, or
set of overloaded elements, in a base class. Optional.
• MustInherit specifies that the class can be used only as a base class and that you cannot
create an object directly from it, i.e., an abstract class. Optional.
• NotInheritable specifies that the class cannot be used as a base class.
• Partial indicates a partial definition of the class.
• Inherits specifies the base class it is inheriting from.
• Implements specifies the interfaces the class is inheriting from.
Notes Complied by E. Wachira
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:
Step 3) Run the code by clicking the Start button from the toolbar. You should get the following
window:
Notes Complied by E. Wachira
We have used the following code:
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.
Notes Complied by E. Wachira
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.
A Rectangle Class in VB.Net
For example, let us consider a Rectangle object. It has attributes like length and width.
Depending upon the design, it may need ways for accepting the values of these attributes,
calculating area and displaying details.
Let us look at an implementation of a Rectangle class and discuss VB.Net basic syntax on the
basis of our observations in it:
Notes Complied by E. Wachira
When the above code is compiled and executed, it produces the following result
Length: 4.5
Width: 3.5
Area: 15.75
Notes Complied by E. Wachira
In previously, we created a Visual Basic module that held the code. Sub Main indicates the entry
point of VB.Net program. Here, we are using Class that contains both code and data. You use
classes to create objects. For example, in the code, r is a Rectangle object.
An object is an instance of a class
Dim r As New Rectangle ()
A class may have members that can be accessible from outside class, if so specified. Data
members are called fields and procedure members are called methods.
Shared methods or static methods can be invoked without creating an object of the class.
Instance methods are invoked through an object of the class
Notes Complied by E. Wachira