Beruflich Dokumente
Kultur Dokumente
ANDHRA PRADESH
Name : K SREE RAMACHARYULU
Designation : LECTURER
Branch : Commercial & Comp. Practice
Institute : Govt. Polytechnic, SRIKAKULAM
Year / Semester :V
Subject : Visual Basic-I
Subject Code : CCP-503
Topic : Programming Fundamentals
Duration : 50 Minutes
Sub. Topic : Multi Dimensional arrays in VB
Teaching Aids : Animation Clips & Images, MS-Office
CCP503.28 to 29 1
Objectives
CCP503.28 to 29 2
RECAP
CCP503.28 to 29 3
MULTI DIMENSIONAL ARRAY
CCP503.28 to 29 4
Two dimensional Array
Suppose it becomes necessary to store ages of 10 students of
CCP Iyear and CCP II year students
You can declare the two dimensional array to store the above
data as follows
0th
Rows
CCP503.28 to 29 5
In the above, the age of CCPI year are stored
in 0th row, from 0th column to 9th column and
CCPI year students data are stored in 1st row
CCP503.28 to 29 6
Two-dimensional ARRAY
Elements in the two dimensional array can be accessed
with the row and column address
Age(0,0) is the address at 1st column in 1st row
Age (0,1) to Age (0,9) are remained elements in first row
Age (1,0) is the address at 1st column in second row
Age (1,1) to Age (1,9) are the address of remaining
column in 2nd row
CCP503.28 to 29 7
Nested loops can be used to generate address of
elements of two dimensions for storing and retrieving
data from the arrays
The following code can help in storing data into the two
dimensional array
Dim age (2,10) as integer
Dim I as Integer, j as integer
For I = 0 to 1
For j = 0 to 9
Age (i, j) = input box (“give age:”)
Next j
Next i
CCP503.28 to 29 8
Two dimensional Arrays
The following code declare two dimension array and one
dimensional array to store names and ages of CCPI and
CCPII year students and shows the output on the screen
Dim Sname (2) as string
Dim age (2,10) as Integer
Dim I as Integer, J as Integer
For I = 0 to 1
sname (I) = Input box (“Give name:”)
For J = 0 to 9
Age (I,J) = Input box (“Give marks:”)
Next J
Next I
For I = 0 to 1
PRINT Sname (I);
For J = 0 to 9
PRINT Age (I,J);
Next J
Next I
PRINT
CCP503.28 to 29 9
(2) Dynamic Arrays
Sometimes we may not know how large to make
an array
CCP503.28 to 29 10
If the data in memory is no longer needed, we can discard
the data and return the resources it occupies
CCP503.28 to 29 11
Redim statement can appear only once in code
CCP503.28 to 29 12
The subsequent ReDim statements can change the
bounds of the array of matrix, but not number of its
dimensions
Preserve Keyword:
CCP503.28 to 29 13
Constants
Some variables don’t change the value during the
execution of a program,Thes values are called
constants
For instance, if our program does math calculations,
the value of pi(3.14159) may appear many times in
our code
CCP503.28 to 29 14
DECLARATION OF CONSTANTS
CCP503.28 to 29 15
ADVANTAGES OF CONSTANTS
CCP503.28 to 29 16
Constants are processed faster than
variables:
CCP503.28 to 29 17
Summary
Types of Arrays
Constants
Array
CCP503.28 to 29 18
Frequently Asked Questions
What is a Multi Dimensional Array? How will you
declare it VB?
CCP503.28 to 29 19
Quiz
A. Dim Mat{1 to 3, 1 To 3}
B. Dim Mat (1 to 3, 1to 3)
C. Dim Mat[3][3]
D. Dim Mat [3, 3]
CCP503.28 to 29 20
Which of the following Statement is
valid in VB dynamic arrays concept?
CCP503.28 to 29 21
3. Which of the following is correct for constant?
CCP503.28 to 29 22
Assignment
CCP503.28 to 29 23