0% found this document useful (0 votes)
29 views27 pages

Lecture One-1

Uploaded by

David Ezekiel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views27 pages

Lecture One-1

Uploaded by

David Ezekiel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

OBJECT ORIENTED PROGRAMMING

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

Upon successful completion of this course, the student will:

 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

VB.NET is a simple, multi-paradigm object-oriented programming language


designed to create a wide range of Windows, Web, and mobile applications
built on the .NET Framework. This lecture covers all the basic and
advanced concepts of VB.NET such as features, strings, arrays,
program flow control, file and exception handling, events, forms,
buttons and more.
WHAT IS VB.NET 5
The VB.NET stands for Visual Basic. Network Enabled Technologies. It is a simple, high-level,
object-oriented programming language developed by Microsoft in 2002. It is a successor of
Visual Basic 6.0, which is implemented on the Microsoft .NET framework. Furthermore, it
supports the OOPs concept, such as abstraction, encapsulation, inheritance, and polymorphism.
Therefore, everything in the VB.NET language is an object, including all primitive data types
(Integer, String, char, long, short, Boolean, etc.), user-defined data types, events, and all objects
that inherit from its base class. It is not a case-sensitive language, whereas, C++, Java, and C#
are case-sensitive languages.

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.

1. It is an object-oriented programming language that follows various oops concepts such as


abstraction, encapsulation, inheritance, and many more. It means that everything in VB.NET
programming will be treated as an object.
2. This language is used to design user interfaces for Windows, mobile, and web-based
applications.

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

1. It is a pure object-oriented programming language based on objects and classes.


However, these features are not available in the previous version of Visual Basic 6. That's
why Microsoft launched the VB.NET language.
2. Using the Visual Studio IDE, you can develop a small program that works faster, with a
large desktop and web application.
3. It uses drop and drag elements to create web forms in .NET applications.
4. A VB.NET can automatically structure your code.
5. It uses a new concept of error handling in the Visual Basic .NET Framework. The new
structure is the try, catch, and finally, method used to handle exceptions as a unit. In
addition, it allows appropriate action to be taken at the place where it encountered an
error.
6. The .NET Framework is a software framework that has a large collection of libraries,
which helps in developing more robust applications.
Disadvantages of VB.NET
DISADVANTAGES OF VB.NET 8
1. The VB.NET programming language is unable to handle pointers directly. Because in this
language, it requires a lot of programming, and it is not easy to manage every address by a
pointer. Furthermore, additional coding takes extra CPU cycles, which increases the
processing time. It shows the slowness of the VB.NET application.

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.

It is used to develop Form-based applications, Web-based applications, and Web services.


There is a variety of programming languages available on the .Net platform, VB.Net and C#
being the most common ones. It is used to build applications for Windows, phones, web,
etc. It provides a lot of functionalities and also supports industry standards.
12
CHARACTERISTICS OF .NET 13
FRAMEWORK
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.

Visual Basic Hello World Program Example


Now, replace your Module1.vb file code like as shown following to display the “Hello World”
message.

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.

The next example shows the differences of Console.WriteLine and Console.Write.


Visual Basic Hello World Program 21
Structure
Now we will go through each step of our visual basic program and learn each parameter in a
detailed manner.

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

Here, Sub Main() is used to define a method in our module (Module1).

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.

As The As clause in the declaration statement allows you to define the


data type.
[Data Type] t’s a type of data the variable can hold, such as integer, string,
decimal, etc.
[Value] Assigning a required value to the variable.
Visual Basic Data Types
DATA TYPE SIZE RANGE
Boolean It depends on the Platform. True or False 25
Byte 1 byte 0 to 255
Char 2 bytes 0 to 65535
Date 8 bytes 0:00:00am 1/1/01 to 11:59:59pm 12/31/9999
Decimal 16 bytes (+ or -)1.0 x 10e-28 to 7.9 x 10e28
Double 8 bytes -1.79769313486232e308 to 1.79769313486232e308
Integer 4 bytes -2,147,483,648 to 2,147,483,647
Long 8 bytes -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
Object 4 bytes on a 32-bit Any type can be stored in a variable of type Object
platform, 8 bytes on a 64-
bit platform
SByte 1 byte -128 to 127
Short 2 bytes -32,768 to 32,767
Visual Basic Data Types

26

DATA TYPE SIZE RANGE


String Depends on Platform 0 to approximately 2 billion Unicode characters
UInteger 4 bytes 0 to 4,294,967,295
ULong 8 bytes 0 to 18,446,744,073,709,551,615 (1.8...E+19 †)
UShort 2 bytes 0 to 65,535
User-Defined Depends on Platform Each member of the structure has a range determined
by its data type and is independent of the ranges of the
other members
Visual Basic Variables 27
In Visual Basic, Variables will represent storage locations, and each variable will have a
particular data type to determine the type of values the variable can hold.

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.

Syntax of Visual Basic Variables Declaration

Following is the syntax of declaring and initializing variables in Visual Basic.

Dim [Variable Name] As [Data Type]


Dim [Variable Name] As [Data Type] = [Value]

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy