[go: up one dir, main page]

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

Lecture One

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
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
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

INTRODUCTION TO .NET AND VB.NET

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.

 It is thus called 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.

 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.

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.
.NET FRAMEWORK OVERVIEW…CONT
11

In summary, 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 application or services
that are available in Microsoft environment.

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.

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