Lecture One-1
Lecture One-1
WITH VB.NET
1
Wisconsin International University College
SON OF MAN
COURSE DESCRIPTION 2
This course is a practical introduction to Visual Basic.Net programming and the services
provided by .NET
It emphasizes the Visual Basic language and how to build Visual Basic applications from
an object-oriented perspective.
Knowledge of the earlier version of the language, Visual Basic 6, is not required .
Each lesson will include practical illustrations (using Visual Studio 2010 or 2013 or
better 2015 or 2017) for understanding concepts, and hands-on programming labs.
This course is a practical introduction to programming in Visual Basic and the use of
services provided by .NET.
It emphasizes the Visual Basic language and how to build Visual Basic applications from
an object-oriented perspective.
SON OF MAN
COURSE OBJECTIVES 3
Be familiar with the architecture of the .NET Framework, and all the basic VB.NET
language constructs.
Get up to speed on the use of the Visual Studio.NET IDE, including debugging, and
application deployment.
Understand how Object-Oriented mechanisms are utilized in VB.NET
Be familiar with the creation of windows applications in VB.NET
Understand how to integrate database access into VB.NET applications
SON OF MAN
INTRODUCTION TO VB.NET 4
Applications built using the VB.NET language are very reliable and scalable, relying on the .NET
Framework to access all libraries that help to execute a VB.NET program. With this language,
you can develop a fully object-oriented application that is similar to an application created
through another language such as C++, Java, or C#. In addition, applications or programs of
VB.NET are not only running on the Windows operating system but can also run on Linux or
Mac OS.
The VB.NET language is designed in such a way that any new beginner or novice and the
advanced programmer can quickly develop a simple, secure, robust, high-performance of web,
VB.NET FEATURES 6
As we know, it is a high-level programming language with many features to develop a secure and
robust application. These are the following features that make it the most popular programming
language.
3. It supports a rapid application development tool kit. In which a developer does not need to write
all the codes as it can get various codes automatically from its libraries. For example, when we
create a form in Visual Basic.net, it automatically calls events of various forms in that class.
4. It is not a case-sensitive language like other languages such as C++, java, etc.
5. It supports Boolean conditions for decision-making in programming.
6. It also supports the multithreading concept, in which you can do multiple tasks at the same
time.
ADVANTAGES OF VB.NET 7
2. The VB.NET programming is easy to learn, which increases a large competition between
the programmers to apply for the same employment or project in VB.NET. Thus, it reduces
a secure job in the programming field as a VB.NET developer.
3. It contains a large collection of libraries for the JIT compiler that helps to interpret an
application. These large libraries hold a vast space in our system that takes more
computing time.
4. Just-In-Time (JIT) compiler: It is the process through which a computer can interpret IL
(intermediate language) compilation and is also required to run your application. It means
that the target computer needs a JIT compiler to interpret a source program in IL, and this
.NET FRAMEWORK OVERVIEW 9
It is a virtual machine that provide a common platform to run an application that was built
using the different language such as C#, VB.NET, Visual Basic, etc. It is also used to create a
form based, console-based, mobile and web-based applications or services that are available
in Microsoft environment. Furthermore, the .NET framework is pure object-oriented, that
similar to the Java language. But it is not a platform independent as Java. So, its application
runs only to the windows platform.
The main objective of this framework is to develop an application that can run on the
windows platform. The current version of the .Net framework is 4.8.
1.The .NET Framework includes two main components: the Common Language Runtime
(CLR) and the .NET Framework Class Library. The CLR is responsible for managing the
execution of code written in any of the supported languages, while the class library
provides a large set of pre-built functions and classes that can be used to create a wide
range of applications.
2. One of the key advantages of the .NET Framework is its support for a variety of
.NET FRAMEWORK OVERVIEW…CONT.
10
3. Another advantage of the .NET Framework is its support for a variety of application types. The
framework includes libraries and tools for creating desktop, web, mobile, and gaming applications,
which makes it a versatile choice for developers working on a wide range of projects.
4. The .NET Framework also provides a number of features that help improve the security, reliability,
and performance of applications. These include features such as code access security, automatic
memory management, and just-in-time (JIT) compilation, which helps improve the speed of
application execution.
5. The .NET Framework is also designed to integrate with other Microsoft technologies, such as
Microsoft SQL Server, Microsoft SharePoint, and Microsoft Office, which can make it easier to build
applications that work seamlessly with other Microsoft products.
.NET FRAMEWORK OVERVIEW…CONT
11
Overall, the .NET Framework is a powerful and versatile development platform that provides
a wide range of tools and libraries for building and running applications on Windows
operating systems.
.NET is a software framework that is designed and developed by Microsoft.
The first version of the .Net framework was 1.0 which came in the year 2002. In easy words,
it is a virtual machine for compiling and executing programs written in different languages
like C#, VB.Net, etc.
Apart from Windows applications, you can use Visual Studio 2015 to build
applications that run in a command prompt window. The command prompt
window isn’t really a DOS window, even though it looks like one. It’s a text
window, and the only way to interact with an application is to enter lines of
text and read the output
generated by the application, which is displayed in this text window, one
line at a time. This type of application is called a console application.
SON OF MAN
CREATE VISUAL BASIC CONSOLE 15
APPLICATION
Using Visual Studio, we can easily create a Hello World Program or Console Application in Visual
Basic based on our requirements.
To create a new application in visual studio, go to the Menu bar, select File à New à select a
Project as shown below.
16
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.
17
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.
18
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
THE CONSOLE OBJECT 19
In VB.NET the console is accessed by the Console object. It has the following methods:
METHODS DESCRIPTION EXAMPLE
WriteLine Outputs a string to the console, Console.WriteLine("str")
and moves the cursor to the next Console.WriteLine()
line.
Write Outputs a string to the console, Console.Write("str")
but do not move the cursor to
the next line.
Clear Clear the content of the console. Console.Clear()
Also moves the cursor to the
top-left corner.
ReadLine Reads a line from the console Dim s As String
(press Enter to finish input). The s = Console.ReadLine()
ReadLine method is also used to
prevent the console
Console.WriteLine and 20
Console.Write
Console.WriteLine and Console.Write are used to output text to the console. These
methods have only one difference: Console.WriteLine moves the cursor to the nextline,
while Console.Write does not.
Calling Console.WriteLine without any argument simply moves the cursor to the nextline.
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.
Visual Basic Hello World Program 22
Sub Main()Structure
The keyword Sub is a procedure and it is helpful to write a series of Visual Basic statements within
Sub and End Sub statements.
The name Main will refer to the name of our method in module (Module1). The Main() method is
the entry point of our console application.
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.
Visual Basic Data Types 23
In Visual Basic, Data Types are useful to define a type of data the variable can hold, such as
integer, float, string, etc., in our application.
Visual Basic is a Strongly Typed programming language. Before we perform any operation
on a variable, it’s mandatory to define a variable with a required data type to indicate what
type of data the variable can hold in our application.
Syntax of Defining Visual Basic Data Types
Following is the syntax of defining data types in visual basic.
Dim [Variable Name] As [Data Type]
Dim [Variable Name] As [Data Type] = [Value]
If you observe the above syntax, we added a required data type after the variable
name to tell the compiler about the type of data the variable can hold.
Visual Basic Data Types 24
ITEM DESCRIPTION
Dim It is useful to declare and allocate the storage space for one or more
variables.
[Variable Name] It’s the variable's name to hold the values in our application.
26
Visual Basic is a Strongly Typed programming language. Before we perform any operation
on variables, it’s mandatory to define the variable with a required data type to indicate the
type of data the variable can hold in our application.
If you observe the above variable declarations, we added a required data type after the
variable name to tell the compiler about the type of data the variable can hold.