2. ARRAYS
An array isacontiguouscollection of
storagelocationsthat aredefined by a
singlename.
Each element of an array hasan unique
number of identification called INDEX
or SUBSCRIPT.
Making changesto any oneelement of
an array doesnot affect other element of
array.
3. Types of array
Single dimensional:
It has only one subscript.
They are used to store data
sequentially.
Only linear data can be presented
in this way.
Eg: roll no of students.
4. Declaring Single Dimension
Array
An array is declared using the following syntax:
Dim ArrayName(MaxIndex) as VariableType
Eg: Dim num(5) as integer
OR
Dim ArrayName(LowerBound To UpperBound) as
VariableType
Eg: Dim num(1 to 5) as integer
The LowerBound of the array is the lowest index in
the array, while the UpperBound is the highest index
in the array
5. Dynamic Arrays
Dynamic array are those whose size is set
at run time.
These type of arrays are very flexible
through which we can manage memory
efficiently.
If some data is no longer needed we can
released the memory occupied by them.
SYNTEX:
Dim arrayname()
ReDim arrayname()
7. -Each time redim statement is
executed
all the values stored in array are
lost.
-All the elements values are reset
like fresh array.
-We can use keyword PRESERVE to
resize the array without losing the
existing data.
8. Syntex:
redim PRESERVE arrayname(index) as integer
example:
redim x(1 to 10) as integer
for j=0 to 10
x(j)= j
print x(j)
next
redim preserve x(1 to 5) as integer
for j=1 to 5
print x(j)
next
9. Multi dimensional array
(two or three)
It has two or more subscripts.
They are easy to manipulate as they
are arranged in rows and columns.
Eg: matrix.
10. Declaring multidimensional
Array
To define a two-dimensional array or table —
Dim statement specifies number of rows and
columns.
The row is horizontal and the column is vertical.
May specify number of elements initial values
Specify row with first subscript, column with
second subscript, and use a comma to specify the
dimensions.
11. The Dim Statement for Two-Dimensional
Arrays — General Form
Dim ArrayName(highestRowSubscript,lowestColumnSubscript)
as VariableType
Eg: dim mat(3,3) as integer
for i=1 to 3
for j=0 to 3
mat(I,j)=inputbox(“enter element rowWise”)
next j
next i
13. Do......Loop
It executes a blocks of statement as
long as condition is true. Condition is
specified with Do is evaluated. if it is
true then statement are executed
otherwise execution continues from
statement written immediately after
Do.....Loop.
14. Do While......Loop
This construct first tests the condition.
If the condition is true only then control enters
the loop otherwise loop is never executed.
If the condition is true then statement written
between Do and Loop are executed as long as
condition remains true. when it becomes false
Loop is terminated and execution continues
from statement.
Syntax:
Do While <condition>
statements
Loop