0% found this document useful (0 votes)
46 views

Unit 3 (A)

This document defines and describes different types of tokens in programming, including keywords, identifiers, literals, and operators. It provides examples of each token type and explains rules for identifiers. It also describes various categories of operators such as arithmetic, relational, logical, bitwise, assignment, and concatenation operators, giving the purpose and syntax for each.

Uploaded by

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

Unit 3 (A)

This document defines and describes different types of tokens in programming, including keywords, identifiers, literals, and operators. It provides examples of each token type and explains rules for identifiers. It also describes various categories of operators such as arithmetic, relational, logical, bitwise, assignment, and concatenation operators, giving the purpose and syntax for each.

Uploaded by

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

⦁ Tokens is the smallest individual unit of a program.

⦁ Types of Token
a. Keywords
b. Identifier
c. Literal
d. Operator
⦁ Keyword are the predefined words that convey a special meaning for
the language compiler. These are known as reserved words
because it convey special meaning.
Eg: DIM, Byte, For, While, class, module, as,etc.,
⦁ Identifiers are the names given to function variable, class, array,
function etc.,
⦁ Rules of Identifier

a. We can use alphabets, digits and special character underscore(_).

b. Keywords cannot be used as Identifier.

c. Digits cannot be used at beginning.

d. White spaces are not allowed.


e. It should not be more than 51 characters

Eg: num, num1, _num1, 1num


⦁ Literal or Constant are the values stored in a variable and it cannot
be changed during programming execution.
⦁ Constant can be of any data type.
⦁ Const is a keyword that is used to declare a variable as constant.

Syntax: Const <var> As <data type>


⦁ operator is a special symbol that tells the compiler to perform the
specific logical or mathematical operation on the data values.
⦁ The data value itself (which can be either a variable or a constant) is
called an operand, and the Operator performs
various operations on the operand.
⦁ Arithmetic Operators
⦁ Relational Operators
⦁ Logical and Bitwise Operators
⦁ Bit Shift Operators
⦁ Assignment Operators
⦁ Concatenation Operators
⦁ Miscellaneous Operators
Operators Description Example

^ It is an exponentiation Operator that is used to raises one Y ^ X (X to the


operand to the power of another operand. power Y)
+ The addition Operator is used to add numeric data, as well X+Y
as concatenate two string variables.
- It is a subtraction Operator, which is used to subtract the X-Y
second operand from the first operand.
* The multiplication Operator is used to multiply the operands X * Y
/ It is a division Operator used to divide one operand by X/Y
another operand and returns a floating-point result.
Mod It is a modulo (Modulus) Operator, which is used to divide X Mod Y
two operands and returns only a remainder.
Operator Description Example

= It checks whether the value of the two operands is equal; If yes, it (A = B)


returns a true value, otherwise it shows False.
<> It is a Non-Equality Operator that checks whether the value of the two (A <> B),
operands is not equal; it returns true; otherwise, it shows false. check Non-
Equality
> A greater than symbol or Operator is used to determine whether the (A > B); if
value of the left operand is greater than the value of the right operand; yes, TRUE,Else
If the condition is true, it returns TRUE; otherwise, it shows FALSE value. FALSE
< It is a less than symbol which checks whether the value of the left (A < B); if
operand is less than the value of the right operand; If the condition is yes, TRUE,Else
true, it returns TRUE; otherwise, it shows FALSE value. FALSE
>= It is greater than equal to which checks two conditions whether the first A >= B
operand is greater than or equal to the second operand; if yes, it returns
TRUE; otherwise, it shows False.
<= This symbol represents less than equal to which determines the first A <= B
operand is less than or equal to the second operand, and if the condition
is true, it returns TRUE; otherwise, it shows FALSE.
⦁ The logical Operator work with Boolean (true or false) conditions,
and if the conditions become true, it returns a Boolean value.

Operator Description Example

AND The And Operator represents, whether (A And B), result =


both the operands are true; the result is False
True.
OR It is an Or Operator that returns a true (A Or B), result = True
value; if anyone operand is true from both
the operands.
NOT The Not Operator is used to reverse the Not AOr
logical condition. For example, if the Not(A And B) is True
operand's logic is True, it reveres the
condition and makes it False.
⦁ 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.
⦁ The Assignment Operators are used to assign the value to variables
in VB.NET.
Operator Description Example

= It is a simple assignment Operator used to assign X = 5, X assign a value 5


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

*= It is a Multiply AND assignment Operator, which multiplies the X *= P, which is


right operand or value with the left operand. And then, the same as X = X - P
result will be assigned to the left operand.
/= It is a Divide AND assignment Operator, which divides the left X /= P, which is
operand or value with the right operand. And then, the result same as X = X - P
will be assigned to the left operand (in floating-point).
\= It is a Divide AND assignment Operator, which divides the left X \= P, which is
operand or value with the right operand. And then, the result same as X = X - P
will be assigned to the left operand (in integer-point division).
^= It is an expression AND assignment Operator, which raises the X ^= P, which is
left operand or value to the right operand's power. And then, same as X = X ^ P
the result will be assigned to the left operand.
&= It is a concatenate string assignment Operator used to bind the Str &= name,
right-hand string or variable with the left-hand string or which is same as
variable. And then, the result will be assigned to the left Str = Str & name
operand.
In VB.NET, there are two concatenation Operators to bind the
operands:

Operator Description Example

& It is an ampersand symbol that is used to bind two or more Result = Wel &
operand together. Furthermore, a nonstring operand can come,
also be concatenated with a string variable ( but in that Result = Welcome
case, Option Strict is on).
+ It is also used to add or concatenate two number or string. Result = Wel +
come,
Result = Welcome
Operator Description Example

GetType A GetType Operator is used to retrieve the type MsgBox(GetType(String).ToStr


of the specified object. In addition, the retrieved ing())
object type provides various information such as
methods, properties, and events.
Function It defines the lambda expression, which declares Console.WriteLine((Function(num
Expression the parameter and code. A Lambda expression is As Integer) num + 1)(5))
a function that is used to calculate and return
value without defining the name.
If The If Operator using short circuit evaluation to Dim a = -4
conditionally return a single object value from Console.WriteLine(If (a >= 0,
two defined object values. The If Operator can be "Positive", "Negative"))
used with two or three defined arguments.
The System Namespaces:

• You can't build a VB .NET application without using classes


from the .NET System
• When you want to use a Windows form, for example, you must
use the System.Windows.Forms. Form class.
• A button in a Windows form comes from the System.Windows.
Forms.Button class, and so on.
• There are many such classes, organized into various
namespaces like System.Windows.Forms.
• System-Includes essential classes and base classes that define commonly used data
types, events and event handlers, interfaces, attributes, exceptions, and so on.
• System.Collections-Includes interfaces and classes that define various collections of
objects, including such collections as lists, queues, arrays, hash tables, and dictionaries.
• System.Data-Includes classes that make up ADO.NET. ADO.NET lets you build data-
handling components that manage data from multiple distributed data sources
• System.Data.OleDb-Includes classes that support the OLE DB .NET data provider.
• System.Data.SqlClient-Includes classes that support the SQL Server .NET data provider.
• System.Diagnostics-Includes classes that allow you to debug your application and to
step through your code. Also includes code to start system processes, read and write
to event logs, and monitor system performance.
• System.Drawing-Provides access to the GDI+ graphics packages that give you access to
drawing methods.
• System.Drawing.Drawing2D-Includes classes that support advanced twodimensional
and vector graphics.
• System.Drawing.Imaging-Includes classes that support advanced GDI+ imaging.
• System.Drawing.Printing-Includes classes that allow you to customize
and perform printing.
• System.Drawing.Text-Includes classes that support advanced GDI+
typography operations. The classes in this namespace allow users to
create and use collections of fonts.
• System.Globalization-Includes classes that specify culture-related
information, including the language, the country/region, calendars,
the format patterns for dates, currency and numbers, the sort order
for strings, and so on.
• System.IO-Includes types that support synchronous and
asynchronous reading from and writing to both data streams and
files.
• System.Net-Provides an interface to many of the protocols used on
the Internet.
• System.Net.Sockets-Includes classes that support the Windows Sockets interface. If
you've worked with the Winsock API, you should be able to develop applications
using the Socket class.
• System.Reflection-Includes classes and interfaces that return information about
types, methods, and fields, and also have the ability to dynamically create and
invoke types.
• System.Security-Includes classes that support the structure of the common language
runtime security system.
• System.Threading-Includes classes and interfaces that enable multithreaded
programming.
• System.Web-Includes classes and interfaces that support browser/server
communication. Included in this namespace are the HTTPRequest class that provides
information about HTTP requests, the HTTPResponse class that manages HTTP
output to the client, and the HTTPServerUtility class that provides access to server-
side utilities and processes. You can also use cookies, support file transfer, and more
with these classes.
• System.Web.Security-Includes classes that are used to implement ASP.NET security in
Web server applications.
• System.Web.Services-Includes classes that let you build and use Web services,
programmable entities on Web Server that code can communicate with using
standard Internet protocols.
• System.Windows.Forms-Includes classes for creating Windows-based forms that
make use of the user interface controls and other features available in the Windows
operating system.
• System.Xml-Includes classes that support processing of XML.
Visual Basic Statements
• A Visual Basic statement is a complete instruction. It can contain:
• keywords—Words reserved for Visual Basic's use.
• operators—Symbols used to perform operations, like +, which performs addition
• operations; -, which performs subtraction operations; and so on.
• variables—Symbolic names given to values stored in memory and declared with
the Dim keyword. For example, if you've declared a variable named
temperature as an Integer type, you can store integer values like 72 or 83 in it.
• literal values—Simple values, like 5 or "Hello."
• constants—The same as variables, except that constants are assigned a value
that cannot then be altered.
• expressions—Combinations of terms and/or keywords that yield a value. For
example, if the variable temperature holds the value 72, then the expression
temperature + 3 yields the value 75.
Each statement is one of the following:
• A declaration statement, which can name and create a variable,
constant, or procedure and can also specify a data type. The data
type can be Boolean, Byte, Char, Date, Decimal, Double, Integer,
Long, Object, Short, Single, or String; or the name of an enumeration
(a series of constants defined at the same time), structure, class, or
interface.
• An executable statement, which can perform an action. These
statements can execute a method or function, or they can loop
through code using one of the Visual Basic loops we'll see in this
chapter, which execute a series of statements repetitively, or they
can be an assignment statement, which assign a value or expression
to a variable or constant such as this: temperature = 72, and so on.
Variables, Constants and Calculations

Data - Variables and Constants


Variable
Memory locations that hold data that can be changed during
project execution
Example: customer’s name
Named Constant
Memory locations that hold data that cannot be changed during
project execution
Example: sales tax rate
• In Visual Basic when you declare a Variable or Named
Constant
An area of memory is reserved
A name is assigned called an Identifier
Follow rules and naming conventions
• Use Declaration Statements to establish Variables and
Constants
Assign name and data type
Not executable unless initialized on same line
Data Types
• Boolean • Short (-32,768 to 32,767)
• Byte (0 to 255) • Integer (-2,147,483,648 to
• Char 2,147,483,647)
• Date • Long (larger whole numbers)
• String • Single (floating point accuracy to 6 digits)
• Decimal • Double (floating point accuracy to 14
• Object digits)
Data Types – Memory Usage
• Boolean – 2 bytes • Short – 2 bytes
• Byte – 1 byte • Integer – 4 bytes
• Char – 2 bytes • Long – 8 bytes
• Date – 8 bytes • Single – 4 bytes
• String – varies • Double – 8 bytes
• Decimal – 16 bytes
• Object – 4 bytes
Naming Variables and Constants
• Must follow Visual Basic Naming Rules
• Should follow Naming Conventions
• Meaningful names
• Include class (data type) of variable
• Use mixed case for variables and uppercase for
constants
Constants

Named
User assigned name, data type and value
Use CONST keyword to declare
Const COMPANY_ADDRESS_String As String = "101 S. Main Street"
Const SALES_TAX_RATE_Decimal As Decimal = .08D

Intrinsic
System defined within Visual Studio
Assigning Values to Constants
Declare the data type of numeric constants by appending a type-declaration
character
• Decimal - D • Long - L
• Double - R • Short - S
• Integer - I • Single - F

Integer – 12345678I Single – 101.25F


Decimal – 850.50D Double – 52875.8R
Long – 134257987L
Declaring Variables
• Declared inside a procedure using a Dim statement
• Declared outside a procedure using Public, Private or Dim statements
• Always declare the variable’s data type
• May declare several variables with one statement
• Use IntelliSense to assist in writing statements
Declaration Examples

Dim customerNameString As String


Private totalSoldInteger As Integer
Dim temperatureSingle As Single
Dim priceDecimal As Decimal
Private priceDecimal As Decimal
Scope and Lifetime of Variables

• Visibility of a variable is its scope


• Scope may be
• Namespace
• Module-level
• Local
• Block-level
• Lifetime of a variable is the period of time the variable exists
• Namespace
• Available to all procedures of project
• Good programming practice excludes use of Namespace
variables
• Module
• Available to all procedures within that module (often a form)
• Use Public or Private keywords
• Place in declaration section of module (form)
• Local
• Available only to the procedure it is declared in
• Declare with Dim keyword and place at top of procedure
• Block (not used until later in this course)
• Available only in block of code where declared
Calculations
• Calculations can be performed with variables, constants, properties of
certain objects, and numeric literals
• Do not use strings in calculations
• Values from Text property of Text Boxes
• Are strings, even if they contain numeric data
• Must be converted to a numeric data type before performing a
calculation
Converting Strings to a Numeric Data Type
• Use Parse methods to convert Text to numeric data
• Each numeric data type class has a Parse method
• Parse method returns a value that can be used in
calculations
• Parse method fails if user enters nonnumeric data or leaves
data blank
Converting to String
• Values assigned to string variables or Text properties must
be string
• Convert any numeric data type to string using .ToString
method
Conversion Methods

Method Convert To
Integer.Parse Integer
Decimal.Parse Decimal
.ToString String
Conversion Examples
quantityInteger = Integer.Parse(quantityTextBox.Text)
priceDecimal = Decimal.Parse(priceTextBox.Text)
wholeNumberInteger = Integer.Parse(digitString)
resultLabel.Text = resultDecimal.ToString( )
countTextBox.Text = countInteger.ToString( )
idString = idInteger.ToString( )
⦁ Tells how much storage/memory to be allocated to a variable
⦁ Types of Data type

a. Boolean values

b. Integers

c. Floating point numbers

d. Strings and characters

e. Date
⦁Boolean datatype can hold only two values one is TRUE and other is
FALSE.
Eg: Dim value As Boolean //variable declaration
value=True
or
value=False
⦁ Integer datatype allows a variable to store whole numbers

Eg: Dim age as Byte


age=24
Dim salary as Integer
Types of Integers
VB Alias .NET Type Size Range

SByte System.SByte 1 -128 to 127


Byte System.Byte 1 0 to 255
Short System.Int16 2 -32768 to 32767
UShort System.UInt16 2 0 to 65,535
Integer System.Int32 4 -2,147,483,648 to 2,147,483,647
UInteger System.UInt32 4 0 to 4,294,967,295
Long System.Int64 8 -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
ULong System.UInt64 8 0 to 18,446,744,073,709,551,615
⦁ Floating datatype allows a variable to store decimal values.

Eg: Dim percentage As Single=78.9


VB Alias .NET Type Size Range Precision

Single System.Single 4 1.5x10-45 to 3.4x1038 7 digits

Double System.Double 8 5.0x10-324 to 1.7x10308 15-16 digits

Decimal System.Decimal 16 1.0x10-28 to 7.9x1028 28-29 digits


⦁ It is used to store textual data like alphabets a-z, A-Z, numbers:0-9 &
symbols.

Eg: Dim username As String=“Lakshman”


Dim age As char=“3”

VB Alias .NET Type Size Range


char System.char 2 Store single character only
String System.String No of Char*2 Stores upto 2 billion characters
⦁ It is used to store date values, time values or date & time values.
⦁ The default values Date: 01/01/0001, Time: 00:00:00
⦁ It occupies 8 bytes of memory space.
Eg: Dim today As Date
today=now() //predefined function for date and time
OR
Dim today As Date
today=#07/20/2002 1:30:00 PM#
Control Flow

Selection Statements Iterative Statements Transfer Statement


 TheIf-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
Statements
End If

Eg: Dim str As String=“JavaTpoint”

If str = "JavaTpoint" Then


Console.WriteLine("Welcome to the JavaTpoint")
End If
 If-Then-Else statement, which executes on block of statements if the
condition is True and another block of statements if the condition is
False.
 Syntax: If condition Then
Statement block1
Else
Statement block2
End If
 Eg: Dim value As Byte=16
If value Mod 2=0 Then
Console.WriteLine(“{0} is even number”,value)
Else
Console.WriteLine(“{0} is odd number”,value)
End If
⦁ If Then ElseIf statement provides a choice to execute only one
condition or statement from multiple statements. In this statement
there is one If condition and multiple ElseIf condition and one Else
block.
⦁ Syntax: If condition1 Then
statement 1
ElseIf condition 2 Then
statement 2
Else
default statement
End If
⦁ Eg: Dim marks As Byte
Console.WriteLine(“Enter the marks”)
marks=Console.ReadLine()
If marks>=85 Then
Console.WriteLine(“The result is Distinction”)
ElseIf marks>=60 Then
Console.WriteLine(“The result is First Class”)
ElseIf marks>=35 Then
Console.WriteLine(“The result is Pass Class”)
Else
Console.WriteLine(“The result is Fail”)
End If
⦁ The select case statement is a collection of multiple case
statements, which allows executing a single case statement from the
list of statements.
⦁ Syntax: Select case [variable/expression]
Case value1
statement1
Case value2
statement2
Case Else
default statement
End Select
⦁ Eg: Dim myInt As Integer
Console.WriteLine(“Please enter an integer”)
myInt=Console.ReadLine()
Select Case myInt
Case 0
Console.WriteLine(“Hello”)
Case 1
Console.WriteLine(“Bye”)
Case Else
Console.WriteLine(“Good Morning”)
End Select
⦁ Defining If block inside another If block.

⦁ Syntax: If Condition 1 Then


Statement 1
If Condition 2 Then
Statement 2
End If
End If
⦁ Eg:
If a = 100 Then
If b = 200 Then
Console.WriteLine("Value of a is {0} and b is {1}“,a,b)
End If
End If
⦁ Repeats a block of statements while a condition is True or until a
condition is True.
⦁ Syntax: Do [{ While | Until } condition ]
[ statements ]
Loop

Or, you can use this syntax:

Do
[ statements ]
Loop [{ While | Until } condition ]
⦁ Eg: Dim x As Byte=1
Do
Console.WriteLine(“The value of the variable is {0}”,x)
x=x+1
Loop While x<=10
⦁ The only difference between do while and do until is that the first one
loops is execute as long as the condition is true, while the second
one loops execute as long as the condition is false.
⦁ Repeats a group of statements a specified number of times.

⦁ Syntax: For counter [ As datatype ] = start To end [ Step step ]


statements
Next
Eg: For i As Integer = 1 To 10 Step 1

Console.WriteLine(" Number is {0} ", i)

Next
⦁ It repeats a group of statements for each element in a array or
collection. This loop is used for accessing and manipulating all
elements in an array or a VB.Net collection.

⦁ Syntax: For Each var_name [As DataType] In Collection_Object


Statements to be executed
Next
Eg: Dim arr() As Integer = {1, 2, 3, 4, 5}
Dim i As Integer

For Each i In arr


Console.WriteLine(" Value of i is {0}", i)
Next
⦁ The While End loop is used to execute blocks of code or
statements in a program, as long as the given condition is true.

Syntax: While condition

Statements

End While
Example: Dim a As Integer = 10
While a < 20
Console.WriteLine("value of a: {0}", a)
a=a+1
End While
⦁ Exit statement is used to terminate the procedure (for, while, do,
select case, function etc.) or exit the procedure and pass control
immediately to the next statement of the termination procedure
⦁ Syntax:
Exit { Do | For | Function | Property | Select | Sub | Try | While }
⦁ Eg:
Dim index As Integer = 0
For index =0 to 10
Console.Writeline(“index value is {0}”,index)
Exit For
End for
⦁ Continue statement is used to skip the particular iteration of the
loop and continue with the next iteration. Generally,
the continue Statement is written inside the body of the For, While
and Do While loop with a condition.
⦁ Syntax:
Continue { Do | For | While }
⦁ Eg: Dim i As Integer = 10

While i < 20

If i = 14 Then
Console.WriteLine(" Skipped number is {0}", i)
i += 1
Continue While
End if
Console.WriteLine(" Value of i is {0}", i)

i += 1
End While
⦁ GoTo statement is known as a jump statement. It is a control
statement that transfers the flow of control to the specified label
within the procedure.
⦁ Syntax:
GoTo label1

label1 is a label used to transfer control to a specified label statement


in a program.
⦁ Eg: Dim num As Integer
Console.WriteLine(" Enter the number :")
num = Console.ReadLine()
If num Mod 2 = 0 Then
GoTo even ' Jump to even label
Else
GoTo odd ' Jump to odd label
End If
odd:
Console.WriteLine(" It is an Odd number")
Console.ReadLine()
return
even:
Console.WriteLine(" It is an Even number ")
Console.ReadLine()
⦁ An array is a linear data structure that is a collection of data
elements of the same type stored on a contiguous
memory location.
⦁ Each data item is called an element of the array. It is a fixed size of
sequentially arranged elements in computer memory with the first
element being at index 0 and the last element at index n
, where n represents the total number of elements in the array.
⦁ In the above diagram, we store the Integer type data elements in an
array starting at index 0. It will continue to store data elements up to
a defined number of elements.
⦁ Syntax: Dim array_name As [Data_Type] ()

⦁ In the above declaration, array_name is the name of an array, and


the Data_Type represents the type of element (Integer, char, String,
Decimal) that will to store contiguous data elements in the VB.NET
array.
⦁ Example:
⦁ 'Store only Integer values
Dim num As Integer()

 ' Declare a single-dimension array of 5 numbers.


Dim num(5) As Integer

⦁ 'Store only String values


Dim name As String() or Dim name(5) As String
⦁ In VB.NET, we can initialize an array with New keyword at the time
of declaration.
⦁ Example:
'Declaration and Initialization of an array elements with size 6

Dim num As Integer() = New Integer(5) { }


Dim num As Integer() = New Integer(5) {1, 2, 3, 4, 5, 6}
Dim num As Integer() = New Integer() {5, 10, 5, 20, 15}
⦁ We can also initialize and declare an array using the following ways
⦁ Example:
Dim arr_name() As Integer = {1, 2, 3, 4, 5}
Dim arr_name() As String = {"Peter", "John", "Brock", "James", "Mari
a"}
Eg: Dim arr As Integer() = New Integer(5) {}

For i As Integer = 0 To 5
Console.WriteLine(" Enter the value for arr[{0}] : ", i)
arr(i) = Console.ReadLine()
Next
Console.WriteLine(" The array elements are : ")

For j As Integer = 0 To 5
Console.WriteLine("{0}", arr(j))
Next
⦁ In VB.NET, a multidimensional array is useful for storing more than
one dimension in a tabular form, such as rows and columns.
⦁ Declaration

Dim arr(3, 1) As Integer „Two Dimensional Array


Or
Dim arr As Integer(,) = New Integer(3, 1) {}
⦁ ' Two Dimensional Integer Array
Dim intarr As Integer(,) = New Integer(2, 1) {{4, 5}, {5, 0}, {3, 1}}

⦁ ' Two Dimensional Integer Array without Dimensions


Dim intarr1 As Integer(,) = New Integer(,) {{4, 5}, {5, 0}, {3, 1}}

⦁ Dim arr(0, 3) As Integer


arr(0, 0) = 12
arr(0, 1) = 13
arr(0, 2) = 14
arr(0, 3) = 15
Eg: Dim arr(1, 3) As Integer

For i As Integer = 0 To 1
For j As Integer = 0 To 3
Console.WriteLine("Enter the value for array[{0}][{1}]", i, j)
arr(i, j) = Console.ReadLine()
Next
Next

For i As Integer = 0 To 1
For j As Integer = 0 To 3
Console.WriteLine("The value of the array is {0}", arr(i, j))
Next
Next
⦁ Dynamic Arrays can resize the capability of the Array at runtime.
when you are in a situation that you do not know exactly the number
of elements to store in array while you making the program.
⦁ It allows us to insert or store the number of elements at runtime in
sequentially manner.
⦁ “ReDim” is the keyword used for resizing

⦁ Initial declaration
Eg: Dim scores() As Integer
⦁ Resizing
Eg: ReDim scores(1)

⦁ If you want to keep the existing items in the Array , you can use the
keyword Preserve .
Eg: ReDim Preserve scores(2)
Eg: 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

You might also like