PDF Version Quick Guide Resources Discussion: Job Search
PDF Version Quick Guide Resources Discussion: Job Search
This tutorial will teach you basic VB.Net programming and will also take
you through various advanced concepts related to VB.Net programming
language.
Audience
This tutorial has been prepared for the beginners to help them
understand basic VB.Net programming. After completing this tutorial,
you will find yourself at a moderate level of expertise in VB.Net
programming from where you can take yourself to next levels.
Prerequisites
VB.Net programming is very much based on BASIC and Visual Basic
programming languages, so if you have basic understanding on these
programming languages, then it will be a fun for you to learn VB.Net
programming language.
Like all other .NET languages, VB.NET has complete support for object-
oriented concepts. Everything in VB.NET is an object, including all of the
primitive types (Short, Integer, Long, String, Boolean, etc.) and user-
defined types, events, and even assemblies. All objects inherits from the
base class Object.
Boolean Conditions
Automatic Garbage Collection
Standard Library
Assembly Versioning
Properties and Events
Delegates and Events Management
Easy-to-use Generics
Indexers
Conditional Compilation
Simple Multithreading
In this chapter, we will discuss the tools available for creating VB.Net
applications.
Windows applications
Web applications
Web services
The last two are free. Using these tools, you can write all kinds of VB.Net
programs from simple command-line applications to more complex
applications. Visual Basic Express and Visual Web Developer Express
edition are trimmed down versions of Visual Studio and has the same
look and feel. They retain most features of Visual Studio. In this tutorial,
we have used Visual Basic 2010 Express and Visual Web Developer (for
the web programming chapter).
The stated purpose of Mono is not only to be able to run Microsoft .NET
applications cross-platform, but also to bring better development tools to
Linux developers. Mono can be run on many operating systems including
Android, BSD, iOS, Linux, OS X, Windows, Solaris and UNIX.
Before we study basic building blocks of the VB.Net programming
language, let us look a bare minimum VB.Net program structure so that
we can take it as a reference in upcoming chapters.
Namespace declaration
A class or module
One or more procedures
Variables
The Main procedure
Statements & Expressions
Comments
Let us look at a simple code that would print the words "Hello World":
Imports System
Module Module1
Sub Main()
Console.WriteLine("Hello World")
Console.ReadKey()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
Hello, World!
Console.WriteLine("Hello World")
You can compile a VB.Net program by using the command line instead of
the Visual Studio IDE:
Object - Objects have states and behaviors. Example: A dog has states - color, name,
breed as well as behaviors - wagging, barking, eating, etc. An object is an instance of
a class.
Class - A class can be defined as a template/blueprint that describes the
behaviors/states that objects of its type support.
Methods - A method is basically a behavior. A class can contain many methods. It is
in methods where the logics are written, data is manipulated and all the actions are
executed.
Instance Variables - Each object has its unique set of instance variables. An object's
state is created by the values assigned to these instance variables.
A Rectangle Class in VB.Net
For example, let us consider a Rectangle object. It has attributes like length and width.
Depending upon the design, it may need ways for accepting the values of these attributes,
calculating area and displaying details.
Let us look at an implementation of a Rectangle class and discuss VB.Net basic syntax on
the basis of our observations in it:
Imports System
'Public methods
length = 4.5
width = 3.5
End Sub
End Function
End Sub
r.Acceptdetails()
r.Display()
Console.ReadLine()
End Sub
End Class
When the above code is compiled and executed, it produces the following result:
Length: 4.5
Width: 3.5
Area: 15.75
In previous chapter, we created a Visual Basic module that held the code. Sub Main
indicates the entry point of VB.Net program. Here, we are using Class that contains both
code and data. You use classes to create objects. For example, in the code, r is a Rectangle
object.
A class may have members that can be accessible from outside class, if so specified. Data
members are called fields and procedure members are called methods.
r.Acceptdetails()
r.Display()
Console.ReadLine()
End Sub
Identifiers
An identifier is a name used to identify a class, variable, function, or any other user-defined
item. The basic rules for naming classes in VB.Net are as follows:
A name must begin with a letter that could be followed by a sequence of letters, digits
(0 - 9) or underscore. The first character in an identifier cannot be a digit.
It must not contain any embedded space or symbol like ? - +! @ # % ^ & * ( ) [ ] { } .
; : " ' / and \. However, an underscore ( _ ) can be used.
It should not be a reserved keyword.
VB.Net Keywords
The following table lists the VB.Net reserved keywords:
Double 8 bytes
-1.79769313486231570E+308 through
-4.94065645841246544E-324, for
negative values
4.94065645841246544E-324 through
1.79769313486231570E+308, for
positive values
8 bytes on 64-bit
platform
Single 4 bytes
-3.4028235E+38 through -1.401298E-45
for negative values;
Example
The following example demonstrates use of some of the types:
Module DataTypes
Sub Main()
Dim b As Byte
Dim n As Integer
Dim si As Single
Dim d As Double
Dim da As Date
Dim c As Char
Dim s As String
Dim bl As Boolean
b = 1
n = 1234567
si = 0.12345678901234566
d = 0.12345678901234566
da = Today
c = "U"c
s = "Me"
bl = True
Else
bl = False
End If
If bl Then
End If
Console.ReadKey()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
U and, Me
1
CBool(expression)
2
CByte(expression)
3
CChar(expression)
4
CDate(expression)
5
CDbl(expression)
Converts the expression to Double data type.
6
CDec(expression)
7
CInt(expression)
8
CLng(expression)
9
CObj(expression)
10
CSByte(expression)
11
CShort(expression)
12
CSng(expression)
13
CStr(expression)
14
CUInt(expression)
15
CULng(expression)
Converts the expression to ULng data type.
16
CUShort(expression)
Example:
The following example demonstrates some of these functions:
Module DataTypes
Sub Main()
Dim n As Integer
Dim da As Date
n = 1234567
da = Today
Console.WriteLine(bl)
Console.WriteLine(CSByte(bl))
Console.WriteLine(CStr(bl))
Console.WriteLine(CStr(da))
Console.WriteLine(CChar(CChar(CStr(n))))
Console.WriteLine(CChar(CStr(da)))
Console.ReadKey()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
True
-1
True
12/4/2012
We have already discussed various data types. The basic value types
provided in VB.Net can be categorized as:
Type Example
Integral types SByte, Byte, Short, UShort, Integer, UInteger, Long, ULong
and Char
Where,
Each variable in the variable list has the following syntax and parts:
Where,
Some valid variable declarations along with their definition are shown
here:
Dim StudentID As Integer
variable_name = value;
for example,
Dim pi As Double
pi = 3.14159
Example
Try the following example which makes use of various types of variables:
Module variablesNdataypes
Sub Main()
Dim a As Short
Dim b As Integer
Dim c As Double
a = 10
b = 20
c = a + b
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
a = 10, b = 20, c = 30
message = Console.ReadLine
Module variablesNdataypes
Sub Main()
message = Console.ReadLine
Console.WriteLine()
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result (assume the user inputs Hello World):
Enter message: Hello World
lvalue : An expression that is an lvalue may appear as either the left-
hand or right-hand side of an assignment.
rvalue : An expression that is an rvalue may appear on the right- but not
left-hand side of an assignment.
Dim g As Integer = 20
20 = g
Constants can be of any of the basic data types like an integer constant,
a floating constant, a character constant, or a string literal. There are
also enumeration constants as well.
The constants are treated just like regular variables except that their
values cannot be modified after their definition.
Declaring Constants
In VB.Net, constants are declared using the Const statement. The Const
statement is used at module, class, structure, procedure, or block level
for use in place of literal values.
Const constantlist
Where,
attributelist: specifies the list of attributes applied to the constants; you can
provide multiple attributes separated by commas. Optional.
accessmodifier: specifies which code can access these constants. Optional.
Values can be either of the: Public, Protected, Friend, Protected Friend, or
Private.
Shadows: this makes the constant hide a programming element of identical
name in a base class. Optional.
Constantlist: gives the list of names of constants declared. Required.
Where, each constant name has the following syntax and parts:
For example,
Example
The following example demonstrates declaration and use of a constant
value:
Module constantsNenum
Sub Main()
Const PI = 3.14149
radius = 7
Console.ReadKey()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
Area = 153.933
Constant Description
vbNullString Not the same as a zero-length string (""); used for calling
external procedures.
memberlist
End Enum
Where,
Each member in the memberlist has the following syntax and parts:
Where,
For example,
Enum Colors
red = 1
orange = 2
yellow = 3
green = 4
azure = 5
blue = 6
violet = 7
End Enum
Example
The following example demonstrates declaration and use of the Enum
variable Colors:
Module constantsNenum
Enum Colors
red = 1
orange = 2
yellow = 3
green = 4
azure = 5
blue = 6
violet = 7
End Enum
Sub Main()
Console.ReadKey()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
Declare Statement
Function Statement
Sub Statement
Declare Statement
Function Statement
Operator Statement
Property Statement
Sub Statement
Declaration Statements
The declaration statements are used to name and define procedures,
variables, properties, arrays, and constants. When you declare a
programming element, you can also define its data type, access level,
and scope.
1 Dim number As
Dim Statement Integer
Dim quantity As
Declares and allocates storage space for one or more Integer = 100
variables. Dim message As
String = "Hello!"
4 Class Statement
Class Box
Declares the name of a class and introduces the
Public length As
definition of the variables, properties, events, and Double
procedures that the class comprises.
Public breadth As
Double
Public height As
Double
End Class
5 Structure Statement
Structure Box
Declares the name of a structure and introduces the
Public length As
definition of the variables, properties, events, and Double
procedures that the structure comprises.
Public breadth As
Double
Public height As
Double
End Structure
6
Module Statement
Public Module
Declares the name of a module and introduces the myModule
InputBox("What is
your name?")
MsgBox("User name
is" & user)
End Sub
End Module
7
Interface Statement
Public Interface
MyInterface
Declares the name of an interface and introduces the
definitions of the members that the interface Sub
doSomething()
comprises.
End Interface
8
Function Statement
Function
Declares the name, parameters, and code that define myFunction
Return 5.87 *
n
End Function
9 Sub Statement
Sub mySub(ByVal s
Declares the name, parameters, and code that define As String)
End Sub
10 Declare Statement
Declare Function
Declares a reference to a procedure implemented in an
getUserName
external file.
Lib "advapi32.dll"
Alias
"GetUserNameA"
ByVal lpBuffer
As String,
ByRef nSize As
Integer) As
Integer
11 Operator Statement
Public Shared
Declares the operator symbol, operands, and code that Operator +
Dim r As
New obj
' implemention
code for r = x + y
Return r
End Operator
12
Property Statement
ReadOnly Property
Declares the name of a property, and the property quote() As String
End Get
End Property
13
Event Statement
Public Event
Declares a user-defined event. Finished()
14
Delegate Statement
Delegate Function
Used to declare a delegate. MathOperator(
ByVal x As
Double,
ByVal y As
Double
) As Double
Executable Statements
An executable statement performs an action. Statements calling a
procedure, branching to another place in the code, looping through
several statements, or evaluating an expression are executable
statements. An assignment statement is a special case of an executable
statement.
Example
Module decisions
Sub Main()
Dim a As Integer = 10
End If
Console.WriteLine("value of a is : {0}", a)
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
value of a is : 10
All these directives begin with #, and only white-space characters may
appear before a directive on a line. These directives are not statements.
Where,
For example,
#Const state = "WEST BENGAL"
Example
Module mydirectives
Sub Main()
#End If
Console.ReadKey()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
This directive allows including external code from an external code file
into a source code file.
[ LogicalLine ]
#End ExternalSource
Example
The following code demonstrates a hypothetical use of the directive:
Module mydirectives
Sub TestExternalSource()
#ExternalSource("c:\vbprogs\directives.vb", 5)
#End ExternalSource
End Sub
End Class
Sub Main()
t.TestExternalSource()
Console.WriteLine("In Main.")
Console.ReadKey()
End Sub
When the above code is compiled and executed, it produces the following
result:
In Main.
The #If...Then...#Else Directives
This directive conditionally compiles selected blocks of Visual Basic code.
statements
[ statements ]
...
[ statements ] ]
[ #Else
[ statements ] ]
#End If
For example,
#Else
#End if
sExample
Module mydirectives
#Const classCode = 8
Sub Main()
#Else
#End If
Console.ReadKey()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
#Region "identifier_string"
#End Region
For example,
#Region "StatsFunctions"
#End Region
An operator is a symbol that tells the compiler to perform specific
mathematical or logical manipulations. VB.Net is rich in built-in operators
and provides following types of commonly used operators:
Arithmetic Operators
Comparison Operators
Logical/Bitwise Operators
Bit Shift Operators
Assignment Operators
Miscellaneous Operators
Arithmetic Operators
Following table shows all the arithmetic operators supported by VB.Net.
Assume variable A holds 2 and variable B holds 7, then:
Show Examples
Comparison Operators
Following table shows all the comparison operators supported by VB.Net.
Assume variable A holds 10 and variable B holds 20, then:
Show Examples
<> Checks if the values of two operands are equal or not; if (A <> B)
values are not equal, then condition becomes true. is true.
> Checks if the value of left operand is greater than the value (A > B)
of right operand; if yes, then condition becomes true. is not
true.
< Checks if the value of left operand is less than the value of (A < B)
right operand; if yes, then condition becomes true. is true.
>= Checks if the value of left operand is greater than or equal (A >= B)
to the value of right operand; if yes, then condition is not
becomes true. true.
<= Checks if the value of left operand is less than or equal to (A <= B)
the value of right operand; if yes, then condition becomes is true.
true.
Apart from the above, VB.Net provides three more comparison operators,
which we will be using in forthcoming chapters; however, we give a brief
description here.
Logical/Bitwise Operators
Following table shows all the logical operators supported by VB.Net.
Assume variable A holds Boolean value True and variable B holds
Boolean value False, then:
Show Examples
And It is the logical as well as bitwise AND operator. If both the (A And
operands are true, then condition becomes true. This B) is
operator does not perform short-circuiting, i.e., it evaluates False.
both the expressions.
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
Assume if A = 60; and B = 13; now in binary format they will be as
follows:
A = 0011 1100
B = 0000 1101
-----------------
We have seen that the Bitwise operators supported by VB.Net are And,
Or, Xor and Not. The Bit shift operators are >> and << for left shift and
right shift, respectively.
Assume that the variable A holds 60 and variable B holds 13, then:
Show Examples
Xor Binary XOR Operator copies the bit if it is set in one (A Xor B)
operand but not both. will give 49,
which is
0011 0001
Not Binary Ones Complement Operator is unary and has the (Not A ) will
give -61,
effect of 'flipping' bits. which is
1100 0011
in 2's
complement
form due to
a signed
binary
number.
<< Binary Left Shift Operator. The left operands value is A << 2 will
moved left by the number of bits specified by the right give 240,
operand. which is
1111 0000
>> Binary Right Shift Operator. The left operands value is A >> 2 will
moved right by the number of bits specified by the right give 15,
operand. which is
0000 1111
Assignment Operators
There are following assignment operators supported by VB.Net:
Show Examples
Str1 =
Str1 &
Str2
Miscellaneous Operators
There are few other important operators supported by VB.Net.
Show Examples
AddressOf Button1_Click
Await AsyncMethod()
'prints 10
Console.WriteLine(add5(5))
Here, operators with the highest precedence appear at the top of the
table, those with the lowest appear at the bottom. Within an expression,
higher precedence operators will be evaluated first.
Show Examples
Operator Precedence
Await Highest
Exponentiation (^)
All comparison operators (=, <>, <, <=, >, >=, Is, IsNot, Like,
TypeOf...Is)
Negation (Not)
If condition Then
[Statement(s)]
End If
c= c+1
End If
If the condition evaluates to true, then the block of code inside the If
statement will be executed. If condition evaluates to false, then the first
set of code after the end of the If statement (after the closing End If) will
be executed.
Flow Diagram:
Example:
Module decisions
Sub Main()
Dim a As Integer = 10
Console.WriteLine("value of a is : {0}", a)
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
a is less than 20
value of a is : 10
Syntax:
The syntax of an If...Then... Else statement in VB.Net is as follows:
If(boolean_expression)Then
Else
End If
If the Boolean expression evaluates to true, then the if block of code will
be executed, otherwise else block of code will be executed.
Flow Diagram:
Example:
Module decisions
Sub Main()
Else
End If
Console.WriteLine("value of a is : {0}", a)
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
value of a is : 100
When using If... Else If... Else statements, there are few points to keep
in mind.
An If can have zero or one Else's and it must come after an Else If's.
An If can have zero to many Else If's and they must come before the
Else.
Once an Else if succeeds, none of the remaining Else If's or Else's will be
tested.
Syntax:
The syntax of an if...else if...else statement in VB.Net is as follows:
If(boolean_expression 1)Then
Else
End If
Example:
Module decisions
Sub Main()
If (a = 10) Then
Console.WriteLine("Value of a is 30")
Else
End If
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
Syntax:
The syntax for a nested If statement is as follows:
If(boolean_expression 2)Then
End If
End If
You can nest ElseIf...Else in the similar way as you have nested If
statement.
Example
Module decisions
Sub Main()
If (a = 100) Then
If (b = 200) Then
End If
End If
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
Syntax:
The syntax for a Select Case statement in VB.Net is as follows:
[ Case expressionlist
[ statements ] ]
[ Case Else
[ elsestatements ] ]
End Select
Where,
Example:
Module decisions
Sub Main()
grade = "B"
Select grade
Case "A"
Console.WriteLine("Excellent!")
Console.WriteLine("Well done")
Case "D"
Console.WriteLine("You passed")
Case "F"
Console.WriteLine("Better try again")
Case Else
Console.WriteLine("Invalid grade")
End Select
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
Well done
Your grade is B
Example
Module decisions
Sub Main()
Select a
Case 100
Select Case b
Case 200
End Select
End Select
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
[ statements ]
[ Continue Do ]
[ statements ]
[ Exit Do ]
[ statements ]
Loop
-or-
Do
[ statements ]
[ Continue Do ]
[ statements ]
[ Exit Do ]
[ statements ]
Example:
Module loops
Sub Main()
Dim a As Integer = 10
Do
Console.WriteLine("value of a: {0}", a)
a = a + 1
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
The program would behave in same way, if you use an Until statement,
instead of While:
Module loops
Sub Main()
Dim a As Integer = 10
Do
Console.WriteLine("value of a: {0}", a)
a = a + 1
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
[ statements ]
[ Continue For ]
[ statements ]
[ Exit For ]
[ statements ]
Next [ counter ]
Example
Module loops
Sub Main()
Dim a As Byte
For a = 10 To 20
Console.WriteLine("value of a: {0}", a)
Next
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
value of a: 20
If you want to use a step size of 2, for example, you need to display only
even numbers, between 10 and 20:
Module loops
Sub Main()
Dim a As Byte
For a = 10 To 20 Step 2
Console.WriteLine("value of a: {0}", a)
Next
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
value of a: 10
value of a: 12
value of a: 14
value of a: 16
value of a: 18
value of a: 20
VB.Net - Each...Next Loop
[ statements ]
[ Continue For ]
[ statements ]
[ Exit For ]
[ statements ]
Next [ element ]
Example
Module loops
Sub Main()
Console.WriteLine(arrayItem)
Next
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
While condition
[ statements ]
[ Continue While ]
[ statements ]
[ Exit While ]
[ statements ]
End While
When the condition becomes false, program control passes to the line
immediately following the loop.
Flow Diagram:
Here, key point of the While loop is that the loop might not ever run.
When the condition is tested and the result is false, the loop body will be
skipped and the first statement after the while loop will be executed.
Example
Module loops
Sub Main()
Dim a As Integer = 10
While a < 20
Console.WriteLine("value of a: {0}", a)
a = a + 1
End While
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
With object
[ statements ]
End With
Example
Module loops
End Class
Sub Main()
With aBook
End With
With aBook
Console.WriteLine(.Name)
Console.WriteLine(.Author)
Console.WriteLine(.Subject)
End With
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
VB.Net Programming
Zara Ali
Information Technology
VB.Net - Nested Loops
VB.Net allows using one loop inside another loop. Following section
shows few examples to illustrate the concept.
Syntax:
The syntax for a nested For loop statement in VB.Net is as follows:
...
Next [ counter2 ]
Next [ counter 1]
While condition1
While condition2
...
End While
End While
...
Loop
Loop
A final note on loop nesting is that you can put any type of loop inside of
any other type of loop. For example, a for loop can be inside a while loop
or vice versa.
Example:
The following program uses a nested for loop to find the prime numbers
from 2 to 100:
Module loops
Sub Main()
Dim i, j As Integer
For i = 2 To 100
For j = 2 To i
Exit For
End If
Next j
Console.WriteLine("{0} is prime", i)
End If
Next i
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
2 is prime
3 is prime
5 is prime
7 is prime
11 is prime
13 is prime
17 is prime
19 is prime
23 is prime
29 is prime
31 is prime
37 is prime
41 is prime
43 is prime
47 is prime
53 is prime
59 is prime
61 is prime
67 is prime
71 is prime
73 is prime
79 is prime
83 is prime
89 is prime
97 is prime
VB.Net - Exit Statement
If you are using nested loops (i.e., one loop inside another loop), the Exit
statement will stop the execution of the innermost loop and start
executing the next line of code after the block.
Syntax:
The syntax for the Exit statement is:
Flow Diagram:
Example:
Module loops
Sub Main()
Dim a As Integer = 10
Console.WriteLine("value of a: {0}", a)
a = a + 1
Exit While
End If
End While
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
For the For...Next loop, Continue statement causes the conditional test
and increment portions of the loop to execute. For the While and
Do...While loops, continue statement causes the program control to pass
to the conditional tests.
Syntax:
The syntax for a Continue statement is as follows:
Flow Diagram:
Example:
Module loops
Sub Main()
Dim a As Integer = 10
Do
If (a = 15) Then
a = a + 1
Continue Do
End If
Console.WriteLine("value of a: {0}", a)
a = a + 1
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19
GoTo label
Flow Diagram:
Example:
Module loops
Sub Main()
Dim a As Integer = 10
Line1:
Do
If (a = 15) Then
a = a + 1
GoTo Line1
End If
Console.WriteLine("value of a: {0}", a)
a = a + 1
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following
result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 16
value of a: 17
value of a: 18
value of a: 19