Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

VB.net project

.NET Framework is a software development platform introduced by Microsoft, designed to run applications built in various languages on Windows. It supports cross-platform development, high performance, and a rich ecosystem with numerous libraries and tools, making it suitable for various application types including web, mobile, and cloud solutions. Key components include the Common Language Runtime (CLR), Base Class Library (BCL), and Framework Class Library (FCL), which provide essential functionalities for developers.

Uploaded by

Avinash Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

VB.net project

.NET Framework is a software development platform introduced by Microsoft, designed to run applications built in various languages on Windows. It supports cross-platform development, high performance, and a rich ecosystem with numerous libraries and tools, making it suitable for various application types including web, mobile, and cloud solutions. Key components include the Common Language Runtime (CLR), Base Class Library (BCL), and Framework Class Library (FCL), which provide essential functionalities for developers.

Uploaded by

Avinash Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Introduction to .

NET Framework :-

The .NET Framework is a software development platform that was introduced by


Microsoft in the late 1990 under the NGWS. On 13 February 2002, Microsoft
launched the first version of the .NET Framework, referred to as the .NET
Framework 1.0.

What is .NET Framework :-


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.

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.

Note: The .NET Framework is not only a language, but it is also a software and
language neutral platform.
Why .Net ?

Choosing .NET as a development platform can be a strategic decision based on its


features, capabilities, and benefits. Here’s a concise summary of why .NET is a
strong choice for many development projects:

1. Cross-Platform Development

 Develop applications that run on Windows, Linux, and macOS using .NET
Core and .NET 5+.
 Create mobile applications for iOS and Android with Xamarin or .NET
MAUI using a shared codebase.

2. Performance and Scalability

 Known for high performance with optimizations like just-in-time (JIT) and
ahead-of-time (AOT) compilation.
 Ideal for building scalable applications, from small projects to enterprise-
grade systems.

3. Versatility

 Supports multiple application types:


 Web Development: With ASP.NET and Blazor.
 Desktop Applications: With WPF and WinForms.
 Mobile Development: With Xamarin and .NET MAUI.
 Cloud Applications: Tight integration with Microsoft Azure.
 IoT and AI Applications: Using tools like ML.NET.

4. Rich Ecosystem and Libraries

 Provides a comprehensive Base Class Library (BCL) for common


functionalities (file I/O, networking, data manipulation).
 Access to specialized frameworks like Entity Framework, ASP.NET, and
ML.NET.

5. Developer Productivity

 Multiple Language Support: Use C#, F#, or VB.NET, giving flexibility to


developers.
 Powerful IDEs: Tools like Visual Studio and Visual Studio Code offer
advanced debugging, IntelliSense, and integration features.
 Code Reuse: Encourages modularity and reusability across projects.

6. Security

 Built-in features for authentication, encryption, and secure data handling.


 Regular updates from Microsoft ensure a secure and stable platform.

7. Strong Community and Microsoft Backing

 An active, global developer community contributes tools, libraries, and


support.
 Backed by Microsoft, ensuring ongoing improvements and long-term
viability.

8. Cost-Effectiveness

 Open Source: .NET Core and .NET 5+ are open source, reducing licensing
costs.
 Integrates seamlessly with Azure, which can save development and
deployment time.

Ideal Use Cases

 Enterprise Applications: For scalability and robustness.


 Web Applications: With modern frameworks like ASP.NET Core.
 Cloud Solutions: When integrated with Azure.
 Mobile Apps: Using Xamarin or .NET MAUI.
 Cross-Platform Applications: With a single codebase across platforms.

Components of .NET Framework

There are following components of .NET Framework:

1. CLR (Common Language Runtime)


2. CTS (Common Type System)
3. BCL (Base Class Library)
4. CLS (Common Language Specification)
5. FCL (Framework Class Library)
6. .NET Assemblies
7. XML Web Services
8. Window Services

CLR (common language runtime)

It is an important part of a .NET framework that works like a virtual component of


the .NET Framework to executes the different languages program like c#, Visual
Basic, etc. A CLR also helps to convert a source code into the byte code, and this
byte code is known as CIL (Common Intermediate Language) or MSIL (Microsoft
Intermediate Language). After converting into a byte code, a CLR uses a JIT
compiler at run time that helps to convert a CIL or MSIL code into the machine or
native code.

MSIL :- The Microsoft Intermediate Language (MSIL), also known as the


Common Intermediate Language (CIL) is a set of instructions that are platform
independent and are generated by the language-specific compiler from the source
code. The MSIL is platform independent and consequently, it can be executed on
any of the Common Language Infrastructure supported environments such as the
Windows .NET runtime.

The MSIL is converted into a particular computer environment specific


machine code by the JIT compiler. This is done before the MSIL can be
executed. Also, the MSIL is converted into the machine code on a requirement
basis i.e. the JIT compiler compiles the MSIL as required rather than the
whole of it.

Execution process in Common Language Runtime (CLR): The execution


process that includes the creation of the MSIL and the conversion of the MSIL
into machine code by the JIT compiler is given as follows:-
 The source code is converted into the MSIL by a language-specific compiler
in the compile time of the CLR. Also, along with the MSIL, metadata is also
produced in the compilation. The metadata contains information such as the
definition and signature of the types in the code, runtime information, etc.
 A Common Language Infrastructure (CLI) assembly is created by assembling
the MSIL. This assembly is basically a compiled code library that is used for
security, deployment, versioning, etc. and it is of two types i.e. process
assembly (EXE) and library assembly (DLL).

JIT –

Just-In-Time compiler(JIT) is a part of Common Language Runtime (CLR) in .NET


which is responsible for managing the execution of .NET programs regardless of
any .NET programming language. A language-specific compiler converts the source
code to the intermediate language. This intermediate language is then converted
into the machine code by the Just-In-Time (JIT) compiler. This machine code is
specific to the computer environment that the JIT compiler runs on.

Working of JIT Compiler: The JIT compiler is required to speed up the code
execution and provide support for multiple platforms. Its working is given as
follows:
The JIT compiler converts the Microsoft Intermediate Language(MSIL) or
Common Intermediate Language(CIL) into the machine code. This is done before
the MSIL or CIL can be executed. The MSIL is converted into machine code on a
requirement basis i.e. the JIT compiler compiles the MSIL or CIL as required rather
than the whole of it. The compiled MSIL or CIL is stored so that it is available for
subsequent calls if required.

Types of Just-In-Time Compiler: There are 3 types of JIT compilers which are as
follows:

 Pre-JIT Compiler: All the source code is compiled into the machine code at
the same time in a single compilation cycle using the Pre-JIT Compiler. This
compilation process is performed at application deployment time. And this
compiler is always implemented in the Ngen.exe (Native Image Generator).
 Normal JIT Compiler: The source code methods that are required at run-
time are compiled into machine code the first time they are called by the
Normal JIT Compiler. After that, they are stored in the cache and used
whenever they are called again.

 Econo JIT Compiler: The source code methods that are required at run-time
are compiled into machine code by the Econo JIT Compiler. After these
methods are not required anymore, they are removed. This JIT compiler is
obsolete starting from dotnet 2.0
Advantages of JIT Compiler:

 The JIT compiler requires less memory usage as only the methods that are
required at run-time are compiled into machine code by the JIT Compiler.
 Page faults are reduced by using the JIT compiler as the methods required
together are most probably in the same memory page.
 Code optimization based on statistical analysis can be performed by the JIT
compiler while the code is running.

Disadvantages of JIT compiler:

 The JIT compiler requires more startup time while the application is executed
initially.
 The cache memory is heavily used by the JIT compiler to store the source
code methods that are required at run-time.

CTS (Common Type System)

It specifies a standard that represent what type of data and value can be defined and
managed in computer memory at runtime. A CTS ensures that programming data
defined in various languages should beinteract with each other to share information.
For example, in C# we define data type as int, while in VB.NET we define integer
as a data type.

BCL (Base Class Library)

The base class library has a rich collection of libraries features and functions that
help to implement many programming languages in the .NET Framework, such as
C #, F #, Visual C ++, and more. Furthermore, BCL divides into two parts:

1. User defined class library


o Assemblies - It is the collection of small parts of deployment an
application's part. It contains either the DLL (Dynamic Link Library) or
exe (Executable) file.
o In LL, it uses code reusability, whereas in exe it contains only
output file/ or application.
o DLL file can't be open, whereas exe file can be open.
o DLL file can't be run individually, whereas in exe, it can run
individually.
o In DLL file, there is no main method, whereas exe file has main
method.
2. Predefined class library
o Namespace - It is the collection of predefined class and method that
present in .Net. In other languages such as, C we used header files, in
java we used package similarly we used "using system" in .NET, where
using is a keyword and system is a namespace.
CLS (Common language Specification)

It is a subset of common type system (CTS) that defines a set of rules and
regulations which should be followed by every language that comes under the .net
framework. In other words, a CLS language should be cross-language integration or
interoperability. For example, in C# and VB.NET language, the C# language
terminate each statement with semicolon, whereas in VB.NET it is not end with
semicolon, and when these statements execute in .NET Framework, it provides a
common platform to interact and share information with each other.

Microsoft .NET Assemblies

A .NET assembly is the main building block of the .NET Framework. It is a small
unit of code that contains a logical compiled code in the Common Language
infrastructure (CLI), which is used for deployment, security and versioning. It
defines in two parts (process) DLL and library (exe) assemblies. When the .NET
program is compiled, it generates a metadata with Microsoft Intermediate
Language, which is stored in a file called Assembly.

FCL (Framework Class Library) -

It provides the various system functionality in the .NET Framework, that includes
classes, interfaces and data types, etc. to create multiple functions and different
types of application such as desktop, web, mobile application, etc. In other words, it
can be defined as, it provides a base on which various applications, controls and
components are built in .NET Framework.

 Data management: Working with collections (lists, dictionaries),


manipulating strings, performing calculations. (e.g., System.Collections,
System.Text, System.Math)
 File and I/O: Reading and writing files, accessing the file system. (e.g.,
System.IO)
 Networking: Building web applications, communicating over networks. (e.g.,
System.Net)
 Windows Forms: Creating desktop applications with buttons, text boxes, etc.
(e.g., System.Windows.Forms)
 Security: Implementing authentication and authorization features. (e.g.,
System.Security)

Benefits of using the FCL:

 Saves development time: You don't need to write everything from scratch,
use pre-built functionalities.
 Increases code consistency: Standardizes coding practices across projects.
 Improves code reliability: Tested code from Microsoft reduces bugs.

Getting started with the FCL in VB.NET:

1. Understanding Namespaces: The FCL is organized into namespaces, which


group related classes. You need to reference the relevant namespace in your
VB.NET code to use its functionalities. (e.g., Imports System.IO for file
operations).
2. Using Classes: Each class represents a specific functionality. You create
objects of a class and use its methods and properties to perform tasks. (e.g.,
Dim file As New StreamWriter("data.txt") creates a StreamWriter object for
writing to a file).

Namespaces

Think of namespaces as folders in a filing system. They provide a way to group


related classes, structures, modules, interfaces, enumerations, and even other
namespaces, preventing naming conflicts and promoting better code organization.

Benefits of Namespaces:

 Prevent Naming Conflicts: Namespaces avoid confusion when you have


elements with the same name. For example, both the .NET Framework and
your own code might have a class named "Math." By using namespaces, you
can differentiate between them.
 Improved Code Organization: Namespaces categorize code based on
functionality, making it easier to understand and maintain large projects.
Imagine a separate namespace for data access, UI elements, and networking
instead of everything jumbled together.
 Easier Code Reuse: By grouping related functionalities within namespaces,
you can easily reuse them across different projects.

Types of Namespaces in VB.NET:

While VB.NET doesn't have different "types" of namespaces in a strict sense, there
are ways to categorize them based on their source:

 .NET Framework Namespaces: The .NET FCL (Framework Class Library)


provides a vast collection of pre-written code organized into namespaces like
System.IO for file handling, System.Windows.Forms for building desktop
applications, and many more. You reference these namespaces in your code to
access their functionalities.
 Custom Namespaces: You can create your own namespaces to organize your
application's code. This is particularly helpful for larger projects to improve
readability and maintainability. You define custom namespaces using the
Namespace keyword followed by your chosen name.

Ex :-
Namespace SpecialSpace
Namespace System
Class abc
Function getValue() As System.Int32
Dim n As System.Int32
Return n
End Function
End Class
End Namespace
End Namespace
VB.NET Data Type
In VB.NET, data type is used to define the type of a variable or function in a program. Furthermore, the
conversion of one data type to another type using the data conversion function.

A Data Type refers to which type of data or value is assigning to a variable or function so that a variable
can hold a defined data type value. For example, when we declare a variable, we have to tell the compiler
what type of data or value is allocated to different kinds of variables to hold different amounts of space in
computer memory.

Syntax:- Dim Variable_Name as DataType

Different Data Types and their allocating spaces in VB.NET


The following table shows the various data types list in the VB.NET programming language.

Data Types Required Space Value Range

Boolean A Boolean type depends True or False


on the implementing
platform

Byte 1 byte Byte Range start from 0 to 255 (unsigned)

Char 2 bytes Char Range start from 0 to 65535


(unsigned)

Date 8 bytes Date range can be 0:00:0 (midnight)


January 1, 0001 to 11:5959 PM of
December 31, 9999.

Decimal 16 bytes Range from 0 to +/-


79,228,162,514,264,337,593,543,950,335
(+/-7.9…E+28) without any decimal point;
And 0 to +/-
7.92281625142264337593543950335 with
28 position to the right of the decimal

Double 8 bytes -1.79769313486231570E+308 to -4.94-


65645841246544E-324 for negative values;
4.94065645841246544E-324 to
1.79769313486231570E+308, for positive
values

Integer 4 bytes -2,147,483,648 to 2,147,483,647 (signed)

Long 8 bytes -9,223,372,036,854,775,808 to


9,223,372,036,854,775,807 (9.2…E + 18)
(signed)
Object Object size based on the It can store any type of data defined in a
platform such as 4 bytes variable of type Object
in 32-bit and 8 bytes in 64-
bit platform

SByte 1 byte -128 to 127 (signed)

Short 2 bytes -32,768 to 32,767 (signed)

Single 4 bytes -3.4028235E + 38 to -1.401298E-45 for


negative values;
And for positive value: 1.401298E-45 to
3.4028235E + 38.

String String Datatype depend It accepts Unicode character from 0 to


on the implementing approximately 2 billion characters.
platform

UInteger 4 bytes The range start from 0 to 4,294,967,295


(unsigned)

ULong 8 bytes The range of ULong start from 0 to


18,446,744,073,709,551,615 (1.8…E + 19)
(unsigned)

User-Defined (structure) A user-defined data type Each member of the structure has its own
depends on the data type and limits independent of the
implementing platform other members' ranges.

UShort 2 bytes Range from 0 to 65,535 (unsigned)

Example :-

Module Data_type
Sub Main()
Dim b As Byte = 1
Dim num As Integer = 5
Dim si As Single
Dim db As Double
Dim get_date As Date
Dim c As Char
Dim str As String
b=1
num = 20
si = 0.12
db = 2131.787
get_date = Today
c = "A"
str = "Hello Friends..."
Console.WriteLine("Welcome to the NSU")
Console.WriteLine("Byte is: {0}", b)
Console.WriteLine("Integer number is: {0}", num)
Console.WriteLine("Single data type is: {0}", si)
Console.WriteLine("Double data type is: {0}", db)
Console.WriteLine("Today is: {0}", get_date)
Console.WriteLine("Character is: {0}", b)
Console.WriteLine("String message is: {0}", str)
Console.ReadKey()
End Sub
End Module

VB.NET Operators

In VB.NET programming, the Operator is a symbol that is used to perform various


operations on variables. VB.NET has different types of Operators that help in
performing logical and mathematical operations on data values. The Operator
precedence is used to determine the execution order of different Operators in
the VB.NET programming language.

Different Types of VB.NET Operators


Following are the different types of Operators available in VB.NET:
 Arithmetic Operators
 Comparison Operators
 Logical and Bitwise Operators
 Bit Shift Operators
 Assignment Operators
 Concatenation Operators
 Arithmetic Operators
The Arithmetic Operators in VB.NET, used to perform mathematical
operations such as subtraction, addition, multiplication, division, etc. on the
operands in VB.NET. These are as follows:
Operators Description Example

^ It is an exponentiation Operator Y ^ X (X to the power Y)


that is used to raises one operand
to the power of another operand.

+ The addition Operator is used to X+Y


add numeric data, as well as
concatenate two string variables.

- It is a subtraction Operator, which X-Y


is used to subtract the second
operand from the first operand.

* The multiplication Operator is used X*Y


to multiply the operands

/ It is a division Operator used to X/Y


divide one operand by another
operand and returns a floating-
point result.

\ It is an integer division Operator, X\Y


which is similar to division
Operator, except that it returns an
integer result while dividing one
operand to another operand.

Mod It is a modulo (Modulus) Operator, X Mod Y


which is used to divide two
operands and returns only a
remainder.

Example :-
Sub Main()
'Declare a, b And c as integer Data Type()
Dim a, b, c As Integer
a = 17
b=4
' Use of + Operator
c=a+b
Console.WriteLine(" Sum of a + b is {0}", c)
'Use of - Operator
c=a-b
Console.WriteLine(" Subtraction of a - b is {0}", c)
'Use of * Operator
c=a*b
Console.WriteLine(" Multiplication of a * b is {0}", c)
'Use of / Operator
d=a/b
Console.WriteLine(" Division of a / b is {0}", d)
'Use of \ Operator
c=a\b
Console.WriteLine(" Similar to division Operator (return only integer value) of
a - b is {0}", c)
'Use of Mod Operator
c = a Mod b
Console.WriteLine(" Modulus of a Mod b is {0}", c)
'Use of ^ Operator
c=a^b
Console.WriteLine(" Power of a ^ b is {0}", c)
End Sub

 Comparison Operators
As the name suggests, the Comparison Operator is used to compare the value of
two variables or operands for the various condition such as greater, less than or
equal, etc. and returns a Boolean value either true or false based on the condition.

Operator Description Example

= It checks whether the value of the (A = B)


two operands is equal; If yes, it
returns a true value, otherwise it
shows False.

<> It is a Non-Equality Operator that (A <> B), check Non-Equality


checks whether the value of the
two operands is not equal; it
returns true; otherwise, it shows
false.

> A greater than symbol or (A > B); if yes, TRUE,


Operator is used to determine
whether the value of the left Else FALSE
operand is greater than the value
of the right operand; If the
condition is true, it returns TRUE;
otherwise, it shows FALSE value.

< It is a less than symbol which (A < B); if the condition is true,
checks whether the value of the returns TRUE else FALSE
left operand is less than the value
of the right operand; If the
condition is true, it returns TRUE;
otherwise, it shows FALSE value.
>= It is greater than equal to which A >= B
checks two conditions whether
the first operand is greater than
or equal to the second operand; if
yes, it returns TRUE; otherwise, it
shows False.
<= This symbol represents less than A <= B
equal to which determines the
first operand is less than or equal
to the second operand, and if the
condition is true, it returns TRUE;
otherwise, it shows FALSE.
Is The Is Operator is used to result = obj1 Is obj2
validate whether the two objects
reference the same variable or
object; If the test is true, it returns
True; otherwise, the result is
False. In short, it checks the
equality of the objects. An Is
Operator is also used to
determine whether the object
refers to a valid object.
IsNot The IsNot Operator is similar to Is Result = obj1 IsNot obj2
Operator, except that the two
object references the different
object; if yes, the result is True;
otherwise, the result is False.
Like The Like Operator is used to result = string Like the pattern,
check the pattern expression of the pattern represents the
string variable; And if the pattern series of characters used by
matched, the result is True; Like Operator.
otherwise, it returns False.

Example :-
Sub Main()
'declaration of Integer, Object and String Data Type variables
Dim x As Integer = 5
Dim y As Integer = 10
Dim Result, obj, obj2 As Object
Dim str, str2 As String
str = "Apple12345"
str2 = "Apple12345"
obj = 10
obj2 = 20
Console.WriteLine(" Program of Comparison Operator")
'Use of > Operator
Console.WriteLine(" Output of x > y is {0}", x > y)
'Use of < Operator
Console.WriteLine(" Output of x < y is {0}", x < y)
'Use of = Operator
Console.WriteLine(" Output of x = y is {0}", x = y)
'Use of <> Operator
Console.WriteLine(" Output of x <> y is {0}", x <> y)
'Use of >= Operator
Console.WriteLine(" Output of x >= y is {0}", x >= y)
'Use of <= Operator
Console.WriteLine(" Output of x <= y is {0}", x <= y)
'Use of Is Operator
Result = obj Is obj2
Console.WriteLine(" Output of obj Is obj2 is {0}", Result)
'Use of Is Operator
Result = obj IsNot obj2
Console.WriteLine(" Output of obj IsNot obj2 is {0}", Result)
'Use of Like Operator
Result = str Like str2
Console.WriteLine(" Output of str Like str2 is {0}", Result)
End Sub
 Logical and Bitwise Operators
The logical and bitwise Operators work with Boolean (true or false)
conditions, and if the conditions become true, it returns a Boolean value. The
following are the logical and bitwise Operators used to perform the various
logical operations such as And, Or, Not, etc. on the operands (variables).
Suppose there are two operand A and B, where A is True, and B is False.

Operator Description Example

And The And Operator represents, (A And B), result = False


whether both the operands are
true; the result is True.

Or It is an Or Operator that returns (A Or B), result = True


a true value; if anyone operand
is true from both the operands.

Not The Not Operator is used to Not A


reverse the logical condition.
For example, if the operand's Or
logic is True, it reveres the
condition and makes it False. Not(A And B) is True

Xor It is an Exclusive OR Operator A Xor B is True


that represents, whether both
the expression is true or false,
the result is True; otherwise, the
result is False.
AndAlso It is a logical AND Operator that A AndAlso B = False
performs short-circuit operation
on the variables, and if both the
operands are true, the result is
True else the result is False.
OrElse It is a logical OR Operator that A OrElse B = True
perform short-circuit operation
on Boolean data. If anyone of
the operand is true, the result is
True else the result is False.
IsFalse The IsFalse Operator is used to
determine whether an
expression is False.
IsTrue The IsTrue Operator is used to
determine whether an
expression is True.
Example :-

Sub Main()
Dim A As Boolean = True
Dim B As Boolean = False
Dim c, d As Integer
c = 10
d = 20
'Use of And Operator
If A And B Then
Console.WriteLine(" Operands A And B are True")
End If
'Use of Or Operator
If A Or B Then
Console.WriteLine(" Operands A Or B are True")
End If
'Use of Xor Operator
If A Xor B Then
Console.WriteLine(" Operands A Xor B is True")
End If
'Use of And Operator
If c And d Then
Console.WriteLine(" Operands c And d is True")
End If
'Use of Or Operator
If c Or d Then
Console.WriteLine(" Operands c Or d is True")
End If
'Use of AndAlso Operator
If A AndAlso B Then
Console.WriteLine(" Operand A AndAlso B is True")
End If
'Use of OrElse Operator
If A OrElse B Then
Console.WriteLine(" Operand A OrElse B is True")
End If
'Use of Not Operator
If Not (A And B) Then
Console.WriteLine(" Output of Not (A And B) is True")
End If
End Sub

 Bit Shift Operators


The Bit Shit Operators are used to perform the bit shift operations on
binary values either to the right or to the left.

Operator Description

AND The Binary AND Operator are used to copy the


common binary bit in the result if the bit exists in
both operands.

OR The Binary OR Operator is used to copy a


common binary bit in the result if the bit found in
either operand.

XOR The Binary XOR Operator in VB.NET, used to


determine whether a bit is available to copy in
one operand instead of both.

Not The binary NOT Operator is also known as the


binary Ones' Compliment Operator, which is
used to flip binary bits. This means it converts the
bits from 0 to 1 or 1 to 0 binary bits.

<< The Binary Left Shift Operator is used to shift the


bit to the left side.

>> The Binary Right Shift Operator is used to shift


the bit to the right side.

Example ;-

Sub Main()
Dim x, y, z As Integer
x = 12
y = 25
Dim a, b As Double
a = 5 ' a = 5(00000101)
b = 9 ' b = 9(00001001)
' Use of And Operator
z = x And y
Console.WriteLine(" BitShift Operator x And y is {0}", z)
'Use of Or Operator
z = x Or y
Console.WriteLine(" BitShift Operator x Or y is {0}", z)
z = x Xor y
Console.WriteLine(" BitShift Operator x Xor y is {0}", z)
z = Not y
Console.WriteLine(" BitShift Operator Not y is {0}", z)
'Use of << Left-Shift Operator
' Output is 00001010
Console.WriteLine(" Bitwise Left Shift Operator - a<<1 = {0}", a << 1)
'Output is 00010010
Console.WriteLine(" Bitwise Left Shift Operator - b<<1 = {0}", b << 1)
'Use of >> Right-Shift Operator
'Output is 00000010
Console.WriteLine(" Bitwise Right Shift Operator - a>>1 = {0}", a << 1)
'Output is 00000100
Console.WriteLine(" Bitwise Right Shift Operator - b>>1 = {0}", a << 1)
End Sub

 Assignment Operators
The Assignment Operators are used to assign the value to variables in
VB.NET.

Operator Description Example

= It is a simple assignment X = 5, X assign a value 5


Operator used to assign a right- X = P + Q, (P + Q) variables or
side operand or value to a left value assign to X.
side operand.
+= An Add AND assignment X += 5, which means
Operator is used to add the X= X+5 ( 5 will add and assign
value of the right operand to the to X and then result saved to
left operand. And the result is Left X operand)
assigned to the left operand.

-= It is a Subtract AND assignment X -= P, which is same as X = X


Operator, which subtracts the -P
right operand or value from the
left operand. And then, the
result will be assigned to the left
operand.

*= It is a Multiply AND assignment X *= P, which is same as X = X


Operator, which multiplies the -P
right operand or value with the
left operand. And then, the
result will be assigned to the left
operand.

/= It is a Divide AND assignment X /= P, which is same as X = X -


Operator, which divides the left P
operand or value with the right
operand. And then, the result
will be assigned to the left
operand (in floating-point).

\= It is a Divide AND assignment X \= P, which is same as X = X -


Operator, which divides the left P
operand or value with the right
operand. And then, the result
will be assigned to the left
operand (in integer-point
division).

^= It is an expression AND X ^= P, which is same as X = X


assignment Operator, which ^P
raises the left operand or value
to the right operand's power.
And then, the result will be
assigned to the left operand.

&= It is a concatenate string Str &= name, which is same as


assignment Operator used to Str = Str & name
bind the right-hand string or
variable with the left-hand string
or variable. And then, the result
will be assigned to the left
operand.
Example :-

Sub Main()
'Declare variable and b As Integer
Dim A As Integer = 5
Dim B As Integer
Dim Str, name As String
name = "come"
Str = "Wel"
'Use of = Operator
B=A
Console.WriteLine(" Assign value A to B is {0}", B)
'Use of += Operator
B += A
Console.WriteLine(" Output of B += A is {0}", B)
'Use of -= Operator
B -= A
Console.WriteLine(" Output of B -= A is {0}", B)
'Use of *= Operator
B *= A
Console.WriteLine(" Output of B *= A is {0}", B)
'Use of /= Operator
B /= A
Console.WriteLine(" Output of B /= A is {0}", B)
'Use of = Operator
B \= A
Console.WriteLine(" Output of B \= A is {0}", B)
'Use of ^= Operator
B ^= A
Console.WriteLine(" Output of B ^= A is {0}", B)
'Use of &= Operator
Str &= name
Console.WriteLine(" Output of Str &= name is {0}", Str)
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
 Concatenation Operators
In VB.NET, there are two concatenation Operators to bind the operands:

Operator Description Example

& It is an ampersand symbol that Result = Wel & come,


is used to bind two or more Result = Welcome
operand together. Furthermore,
a nonstring operand can also be
concatenated with a string
variable ( but in that case,
Option Strict is on).

+ It is also used to add or Result = Wel + come,


concatenate two number or Result = Welcome
string.

Example :-
Sub Main()
Dim str As String = "Wel"
Dim str2 As String = "come"
Dim str3 As String = " "
Dim str4 As String = "to JavatPoint"
Dim result As String
Dim result2 As String
result = str & str2
Console.WriteLine(" Result = str & str2 gives = {0}", result)
result2 = str + str2 + str3 + str4
Console.WriteLine(" Result = str + str2 + str3 +str4 gives = {0}",
result2.ToString)
End Sub
VB.NET Control Statements
In VB.NET, the control statements are the statements that controls the
execution of the program on the basis of the specified condition. It is useful for
determining whether a condition is true or not. If the condition is true, a single or
block of statement is executed. In the control statement, we will use if- Then, if
Then Else, if Then ElseIf and the Select case statement.

We can define more than one condition to be evaluated by the program with
statements. If the defined condition is true, the statement or block executes
according to the condition, and if the condition is false, another statement is
executed.

The following figure shows a common format of the decision control statements
to validate and execute a statement:

The above diagram shows that if the defined condition is true, statement_1 will be executed, and if the
condition is false, statement_2 will be executed.

VB.NET provides the following conditional or decision-making statements.

 If-Then Statement
 If-Then Else Statement
 If-Then ElseIf Statement
 Select Case Statement
 Nested Select Case Statements
 If-Then Statement
The If-Then Statement is a control statement that defines one or more
conditions, and if the particular condition is satisfied, it executes a piece of
information or statements.

Syntax:
If condition Then
[Statement or block of Statement]
End If

In If-Then Statement, the condition can be a Boolean, logical, or relational condition, and
the statement can be single or group of statements that will be executed when the
condition is true.
Example : Write a simple program to find the greater number in VB.NET.
Sub Main()
Dim a As Integer = 5
Dim b As Integer = 8
If a > b Then
Console.Writeline("A is greater than b ")
End If
End Sub

 If-Then-Else Statement
The If-Then Statement can execute single or multiple statements when
the condition is true, but when the expression evaluates to false, it does nothing. So,
here comes the If-Then-Else Statement. The IF-Then-Else Statement is telling what
If condition to do when if the statement is false, it executes the Else statement.
Following is the If-Then-Else statement syntax in VB.NET as follows:
Syntax:
If (Boolean_expression) Then
'This statement will execute if the Boolean condition is true
Else
'Optional statement will execute if the Boolean condition is false
End If
Flow chart :-

The above diagram represents that if the Boolean expression (condition) is true, the if
statement will execute, and if the Boolean expression is false, Else code or statement will
be executed. After that, the control transfer to the next statement, which is immediately
after the If-Then-Else control statement.
Example :- Write a program to check weather the number is even or odd .
Sub Main()
Dim num As Integer
Console.WriteLine("Enter the Number")
num = Console.ReadLine() 'read data from console
If (num Mod 2 = 0) Then ' if condition is true, print the if statement
Console.WriteLine("It is an even number")
Else 'otherwise, Else statement is executed.
Console.WriteLine("It is an odd number")
End If
Console.WriteLine("press any key to exit...")
Consle.ReadKey()
End Sub

 VB.NET If-Then-ElseIf statement


The If-Then-ElseIf Statement provides a choice to execute only one condition or
statement from multiple statements. Execution starts from the top to bottom, and it
checked for each If condition. And if the condition is met, the block of If the
statement is executed. And if none of the conditions are true, the last block is
executed. Following is the syntax of If-Then-ElseIf Statement in VB.NET as follows:

Syntax

If(condition 1)Then
' Executes when condition 1 is true
ElseIf( condition 2)Then
' Executes when condition 2 is true
ElseIf( boolean_expression 3)Then
' Executes when the condition 3 is true
Else
' executes the default statement when none of the above conditions is true.
End If

Flowchart
The following diagram represents the functioning of the If-Else-If Statement in the
VB.NET programming language.
If this condition is true in the flowchart of the if-else-if statement, the statement is executed within the if
block. If the condition is not true, it passes control to the next ElseIf condition to check whether the
condition is matched. And if none of the conditions are matched, the else block is executed.

Example : Write a program to show the uses of If... ElseIf statements.

Sub Main()
Dim var1 As Integer
Console.WriteLine(" Input the value of var1: ")
var1 = Console.ReadLine()
If var1 = 20 Then
'if condition is true then print the following statement'
Console.WriteLine(" Entered value is equal to 20")
ElseIf var1 < 50 Then
Console.WriteLine(" Entered value is less than 50")
ElseIf var1 >= 100 Then
Console.WriteLine(" Entered value is greater than 100")
Else
'if none of the above condition is satisfied, print the following statement
Console.WriteLine(" Value is not matched with above condition")
End If
Console.WriteLine(" You have entered : {0}", var1)
End Sub

 Select Case Statement

In VB.NET, the Select Case statement is a collection of multiple case statements, which
allows executing a single case statement from the list of statements. A selected case
statement uses a variable to test for equality against multiple cases or statements in a
program. If the variable is matched with any test cases, that statement will be executed.
And if the condition is not matched with any cases, it executes the default statement.

Using the select case statement in VB.NET programming, you can replace the uses of
multiple If-Then-Else If statement from the program for better readability and easy to use.

Syntax
Following is the syntax of the Select Case statement in VB.NET, as follows:
Select Case [variable or expression]
Case value1 'defines the item or value that you want to match.
// Define a statement to execute
Case value2 'defines the item or value that you want to match.
// Define a statement to execute
Case Else
// Define the default statement if none of the conditions is true.
End Select

Furthermore, you can also set more than one condition in a single case statement, such as:
Select Case Variable / expression
Case value1
Statement1
Case value2, value3
Statement2
Case Else
// define the default statement if none of the condition is true
End Select

Flowchart of Select Case Statement

The following flowchart represents the functioning of the Select case statement in the
VB.NET programming language.
In Flowchart, the Select Case statement represents the evaluating of the process start from top to
bottom. If the expression or value is matched with the first select case, statement -1 is executed else
the control transfer to the next case for checking whether the expression is matching or not. Similarly,
it checks all Select case statements for evaluating. If none of the cases are matched, the Else block
statement will be executed, and finally, the Select Case Statement will come to an end.

Example 1: Write a program to display the Days name using the select case statement in VB.NET.

Sub Main()
'define a local variable.
Dim Days As String
Days = "Thurs"
Select Case Days
Case "Mon"
Console.WriteLine(" Today is Monday")
Case "Tue"
Console.WriteLine(" Today is Tuesday")
Case "Wed"
Console.WriteLine("Today is Wednesday")
Case "Thurs"
Console.WriteLine("Today is Thursday")
Case "Fri"
Console.WriteLine("Today is Friday")
Case "Sat"
Console.WriteLine("Today is Saturday")
Case "Sun"
Console.WriteLine("Today is Sunday")
Case Else
Console.WriteLine(" You have typed Something wrong")
End Select
Console.WriteLine("You have selected : {0}", Days)
Console.WriteLine("Press any key to exit...")
Console.ReadLine()
End Sub
VB.NET Loop
A Loop is used to repeat the same process multiple times until it meets the specified condition
in a program. By using a loop in a program, a programmer can repeat any number of statements
up to the desired number of repetitions. A loop also provides the suitability to a programmer to
repeat the statement in a program according to the requirement. A loop is also used to reduce
the program complexity, easy to understand, and easy to debug.

Advantages of VB.NET loop


 It provides code iteration functionality in a program.
 It executes the statement until the specified condition is true.
 It helps in reducing the size of the code.
 It reduces compile time.

Types of Loops
There are five types of loops available in VB.NET:
 Do While Loop
 For Next Loop
 For Each Loop
 While End Loop

 Do While Loop
In VB.NET, Do While loop is used to execute blocks of statements in the
program, as long as the condition remains true. It is similar to the While End
Loop, but there is slight difference between them. The while loop initially
checks the defined condition, if the condition becomes true, the while loop's
statement is executed. Whereas in the Do loop, is opposite of the while loop, it
means that it executes the Do statements, and then it checks the condition.

Syntax:
Do
[ Statements to be executed]
Loop While Boolean_expression
// or
Do
[Statement to be executed]
Loop Until Boolean_expression
In the above syntax, the Do keyword followed a block of statements, and While keyword
checks Boolean_expression after the execution of the first Do statement.

Flowchart of Do loop

The above flow chart represents the flow of Do While loop. It is used to control the flow of statements, such that it
executes the statement at least once before checking the While or Until condition. If the condition is true, the next
iteration will be executed till the condition become false.

Example 1. Write a simple program to print a number from 1 to 10 using the Do While loop in VB.NET.

Sub Main()
' Initializatio and Declaration of variable i
Dim i As Integer = 1
Do
' Executes the following Statement
Console.WriteLine(" Value of variable I is : {0}", i)
i = i + 1 'Increment the variable i by 1
Loop While i <= 10 ' Define the While Condition
End Sub

Use of Until in Do Until Loop statement


In the VB.NET loop, there is a Do Until loop statement, which is similar to the Do While
loop. The Do Statement executes as long as Until condition becomes true.
Example: Write a program to understand the uses of Do Until Loop in VB.NET.

sub Main()
' Initialization and Declaration of variable i
Dim i As Integer = 1
Do
' Executes the following Statement
Console.WriteLine(" Value of variable i is : {0}", i)
i = i + 1 'Increment variable i by 1
Loop Until i = 10 ' Define the Until Condition
End Sub

Nested Do While Loop Statement


In VB.NET, when we use one Do While loop inside the body of another Do While loop,
it is called Nested Do While loop.

Syntax
Do
// Statement of the outer loop
Do
// Statement of outer loop
While (condition -2)
// Statement of outer loop
While (condition -1)

Example 2: Write a simple program to use the Do While loop Statement in VB.NET.

Sub Main()
' Declare i and j as Integer variable
Dim i As Integer = 1
Do
' Outer loop statement
Console.WriteLine(" Execution of Outer loop is {0}", i & " times")
Dim j As Integer = 1
Do
'Inner loop statement
Console.WriteLine(" Execution of Inner loop is {0}", j)
j = j + 1 ' Increment Inner Counter variable by 1
Loop While j < 3
Console.WriteLine()
i = i + 1 ' Increment Outer Counter variable by 1
Loop While i < 4
Console.WriteLine(" Exit from the loop")
End Sub

 For Next Loop


A For Next loop is used to repeatedly execute a sequence of code or a block of code until
a given condition is satisfied. A For loop is useful in such a case when we know how
many times a block of code has to be executed. In VB.NET, the For loop is also known
as For Next Loop.

Syntax

For variable_name As [ DataType ] = start To end [ Step step ]


[ Statements to be executed ]
Next
Let's understand the For Next loop in detail.

 For: It is the keyword that is present at the beginning of the definition.


 variable_name: It is a variable name, which is required in the For loop
Statement. The value of the variable determines when to exit from the For-
Next loop, and the value should only be a numeric.
 [Data Type]: It represents the Data Type of the variable_name.
 start To end: The start and end are the two important parameters
representing the initial and final values of the variable_name. These
parameters are helpful while the execution begins, the initial value of the
variable is set by the start. Before the completion of each repetition, the
variable's current value is compared with the end value. And if the value of
the variable is less than the end value, the execution continues until the
variable's current value is greater than the end value. And if the value is
exceeded, the loop is terminated.
 Step: A step parameter is used to determine by which the counter value of a
variable is increased or decreased after each iteration in a program. If the
counter value is not specified; It uses 1 as the default value.
 Statements: A statement can be a single statement or group of statements
that execute during the completion of each iteration in a loop.
 Next: In VB.NET a Next is a keyword that represents the end of the For
loop's
Flowchart of For Next loop
The following flowchart represents the functioning of the For Next loop in the VB.NET
programming language.

In the above flow chart, the first step is to initialize the variable name with the start value.
And then, the value of the variable will be compared to the end expression or value. If the
condition is true, the control enters the loop body and executes the statements. After that,
the value of a variable will be automatically incremented by the compiler. Upon
completion of each iteration, the current value of a variable will be again compared to the
end expression. If the condition is not true, the controlled exit from the loop.

Example 1. Write a simple program to print the number from 1 to 10 using the For Next loop.

Sub Main()
' It is a simple print statement,
Console.WriteLine(" The number starts from 1 to 10 ")
' declare and initialize variable i
For i As Integer = 1 To 10 Step 1
' if the condition is true, the following statement will be executed
Console.WriteLine(" Number is {0} ", i)
' after completion of each iteration, next will update the variable counter
Next
End Sub

Nested For Next Loop in VB.NET


In VB.NET, when we write one For loop inside the body of another For Next loop, it is
called Nested For Next loop.
Syntax:
For variable_name As [Data Type] = start To end [ Step step ]
For variable_name As [Data Type] = start To end [ Step step ]
[ inner loop statements ]
Next
[ Outer loop statements ]
Next

Example :-
Sub Main()
Dim i, j As Integer
For i = 1 To 3
'Outer loop
Console.WriteLine(" Outer loop, i = {0}", i)
'Console.WriteLine()
'Inner loop
For j = 1 To 4
Console.WriteLine(" Inner loop, j = {0}", j)
Next
Console.WriteLine()
Next
End Sub
 For Each Loop
In the VB.NET, For Each loop is used to iterate block of statements in an array or
collection objects. Using For Each loop, we can easily work with collection objects such
as lists, arrays, etc., to execute each element of an array or in a collection. And when
iteration through each element in the array or collection is complete, the control
transferred to the next statement to end the loop.

Syntax:
For Each var_name As [ DataType ] In Collection_Object
[ Statements to be executed]
Next

For Each loop is used to read each element from the collection object or an array. The
Data Type represents the type of the variable, and var_name is the name of the variable to
access elements from the array or collection object so that it can be used in the body of
For Each loop.

Flowchart of For Each loop


The following flowchart represents the For Each Next loop's functioning to iterate
through array elements in the VB.NET programming language.
The first step is to initialize an array or collection object to execute each element of the
array with the help of variables in For Each loop. A variable is used in For Each loop to
checks whether the element is available or not. If the element is available in the collection
object, the For Each block will be executed until the condition remains true. After the
execution of each element of an array, the control transfer to the end statement.

Examples of For Each Loop

Sub Main()
'declare and initialize an array as integer
Dim An_array() As Integer = {1, 2, 3, 4, 5}
Dim i As Integer 'Declare i as Integer
For Each i In An_array
Console.WriteLine(" Value of i is {0}", i)
Next
End Sub

 While End Loop


The While End loop is used to execute blocks of code or statements in a program, as
long as the given condition is true. It is useful when the number of executions of a
block is not known. It is also known as an entry-controlled loop statement, which
means it initially checks all loop conditions. If the condition is true, the body of the
while loop is executed. This process of repeated execution of the body continues until
the condition is not false. And if the condition is false, control is transferred out of the
loop.

Syntax:
While [condition]
[ Statement to be executed ]
End While

Here, condition represents any Boolean condition, and if the logical condition is true,
the single or block of statements define inside the body of the while loop is executed.

Flow Diagram of the While End Loop in VB.NET


As we know, the While End loop is an entry-controlled loop used to determine if the
condition is true, the statements defined in the body of the loop are executed, and the
execution process continues till the condition is satisfied. Furthermore, after each
iteration, the value of the counter variable is incremented. It again checks whether the
defined condition is true; And if the condition is again true, the body of the While loop
is executed. And when the condition is not true, the control transferred to the end of
the loop.

Example: Write a simple program to print the number from 1 to 10 using while End
loop in VB.NET.

Sub Main()
'declare x as an integer variable
Dim x As Integer
x=1
' Use While End condition
While x <= 10
'If the condition is true, the statement will be executed.
Console.WriteLine(" Number {0}", x)
x = x + 1 ' Statement that change the value of the condition
End While
End Sub
Nested While End Loop
In VB.NET, when we write a While End loop inside the body of another While End
loop, it is called Nested While End loop.

Syntax
While (condition -1)
// body of the outer while loop
While (condition -2)
// body of inner while loop
End While
// body of the outer loop
End While

Example :-
Sub Main()
' Declare i and j as Integer variable
Dim i As Integer = 1
While i < 4
' Outer loop statement
Console.WriteLine(" Counter value of Outer loop is {0}", i)
Dim j As Integer = 1
While j < 3
'Inner loop statement
Console.WriteLine(" Counter value of Inner loop is {0}", j)
j = j + 1 ' Increment Inner Counter variable by 1
End While
Console.WriteLine() 'print space
i = i + 1 ' Increment Outer Counter variable by 1
End While
End Sub
Arrays
An array stores a fixed-size sequential collection of elements of the same type. An array
is used to store a collection of data, but it is often more useful to think of an array as a
collection of variables of the same type.

All arrays consist of contiguous memory locations. The lowest address corresponds to the
first element and the highest address to the last element.

Creating Arrays in VB.Net


To declare an array in VB.Net, you use the Dim statement. For example,
Dim intData(30) ' an array of 31 elements
Dim strData(20) As String ' an array of 21 strings
Dim twoDarray(10, 20) As Integer 'a two dimensional array of integers
Dim ranges(10, 100) 'a two dimensional array

You can also initialize the array elements while declaring the array. For example,
Dim intData() As Integer = {12, 16, 20, 24, 28, 32}
Dim names() As String = {"Karthik", "Sandhya", _
"Shivangi", "Ashwitha", "Somnath"}
Dim miscData() As Object = {"Hello World", 12d, 16ui, "A"c}

NOTE :-
 In VB.NET when we create an array of size n then it means the total element store
in the array is n+1 , Because the staring index of an is 0 (zero) like others
programming language but the ending index is n in many programming language
the ending index is n-1 .
 An array declared as Object can store elements of any data type (strings, numbers,
characters, etc.).
Example :-
1.
Sub Main()
Dim n(10) As Integer ' n is an array of 11 integers '
Dim i, j As Integer
' initialize elements of array n '
For i = 0 To 10
n(i) = i + 100 ' set element at location i to i + 100
Next i
' output each array element's value '
For j = 0 To 10
Console.WriteLine("Element({0}) = {1}", j, n(j))
Next j
Console.ReadKey()
End Sub

2.
Sub Main()
Dim n As Integer
Console.Write("enter size of an array :- ")
n = Console.ReadLine()
Dim arr(n) As Integer
For i = 0 To n
Console.Write("enter array at posion {0} - ", i)
arr(i) = Console.ReadLine()
Next
For i = 0 To arr.Length() - 1
Console.WriteLine("array at position {0} - {1}", i, arr(i))
Next
End sub

3. Print array using for each loop


Sub Main()
Dim n As Integer
Console.Write("enter size of an array :- ")
n = Console.ReadLine()
Dim arr(n) As Integer
For i = 0 To n
Console.Write("enter array at posion {0} - ", i)
arr(i) = Console.ReadLine()
Next
For Each i As Integer In arr
Console.WriteLine(i)
Next
End sub
4. Using form
Design -

Code –
Public Class Form1
Dim a As Integer
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim b As Integer = TextBox2.Text
a = TextBox1.Text
Dim x As Integer = ListBox1.Items.Count()
If x <= a Then
ListBox1.Items.Add(b)
End If
End Sub
Public Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim arr(a) As Integer
For i = 0 To a
arr(i) = ListBox1.Items(i)
Next
For i = 0 To a
ListBox2.Items.Add(arr(i))
Next
End Sub
End Class

Dynamic Arrays
Dynamic arrays are arrays that can be dimensioned and re-dimensioned as par the need of
the program. You can declare a dynamic array using the ReDim statement.

Syntax for ReDim statement −


ReDim [Preserve] arrayname(subscripts)

 The Preserve keyword helps to preserve the data in an existing array, when you
resize it.
 arrayname is the name of the array to re-dimension.
 subscripts specifies the new dimension.

Example –
Module arrayApl
Sub Main()
Dim marks() As Integer
ReDim marks(2)
marks(0) = 85
marks(1) = 75
marks(2) = 90
ReDim Preserve marks(10)
marks(3) = 80
marks(4) = 76
marks(5) = 92
marks(6) = 99
marks(7) = 79
marks(8) = 75
For i = 0 To 10
Console.WriteLine(i & vbTab & marks(i))
Next i
Console.ReadKey()
End Sub
End Module

Note –
 while creating dynamic array we have to use preserve keyword if we don’t use
preserve keyword than redim create a new array of same name and delete all
existing element of an array that we store previously .

Multi-Dimensional Arrays
VB.Net allows multidimensional arrays. Multidimensional arrays are also called rectangular
arrays.

You can declare a 2-dimensional array of strings as −


Dim twoDStringArray(10, 20) As String

or, a 3-dimensional array of Integer variables −


Dim threeDIntArray(10, 10, 10) As Integer

Example –
Sub Main()
' an array with 5 rows and 2 columns
Dim a(,) As Integer = {{0, 0}, {1, 2}, {2, 4}, {3, 6}, {4, 8}}
Dim i, j As Integer
' output each array element's value '
For i = 0 To 4
For j = 0 To 1
Console.WriteLine("a[{0},{1}] = {2}", i, j, a(i, j))
Next j
Next i
Console.ReadKey()
End Sub

You might also like