Lecture One
Lecture One
Lecture One
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
WEEK 1 & 2: INTRODUCTION TO .NET
AND VB.NET 4
NET Framework Overview
Overview of Visual Studio.NET Development Environment
The Visual Studio.NET Tools
The Windows Forms Designer
Running a Visual Basic Program
The Properties Window
Getting Help
Creating Console Applications
Writing Your First Program
Creating the User Interface
Setting the Properties
Writing the Code
Debugging Visual Basic.NET Applications
Building an Executable File
SON OF MAN
5
SON OF MAN
WHAT IS VISUAL BASIC
6
Visual Basic (VB) is a widely used programming language developed by Microsoft and
based on earlier BASIC implementations such as QBasic/QuickBasic.
Visual Basic like other modern programming languages allow us to collect a data type
and its associated operations into a single entity called an object.
Non-OOP Languages, like C & COBOL, treat data and operations as separate parts of the
program.
SON OF MAN
WHAT IS VISUAL BASIC
7
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#, and Visual J#. VB.NET treats
everything as an object.
Non-OOP Languages, like C & COBOL, treat data and operations as separate parts of the
program.
SON OF MAN
.NET FRAMEWORK OVERVIEW 8
The .NET Framework is a software development framework developed by Microsoft that
provides a runtime environment and a set of libraries and tools for building and running
applications on Windows operating systems. The framework includes a variety of
programming languages, such as C#, F#, and Visual Basic, and supports a range of
application types, including desktop, web, mobile, and gaming applications.
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
programming languages. This means that developers can choose the language that best fits
their needs and expertise, while still being able to use the same set of libraries and tools
.NET FRAMEWORK OVERVIEW…CONT.
9
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
10
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.
Furthermore, the .NET framework is a pure object oriented, that similar to the Java language.
But it is not a platform independent as the Java. So, its application runs only to the windows
platform.
Visual Studio.NET
12
Development tool that contains a rich set of productivity and
debugging features
• Supports managed and unmanaged applications
• Supports different languages such as C#, C++, VB.NET, …
• Many useful tools and wizards
• Windows Forms Designer
• ASP.NET Web Forms Designer
• SQL Server integration with ADO.NET and XML
Integrated Development Environment
VS.NET is not part of the .NET Framework
SON OF MAN
Visual Studio .NET
13
SON OF MAN
BUILDING A CONSOLE APPLICATION 14
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.