You are on page 1of 29

m   

{Lecturer, Computer Engineering Department }


Ú uactorial of a number ::
Dim num As Double
Dim fact As Long
d 

 
num = Val(Text1.Text)
fact = 1
Do While (num >= 1)
fact = fact * num
num = num - 1
Loop
MsgBox "factorial is ", vbInformation, "factorial
calculation"
Label2.Caption = "factorial is :: " & fact


Ú A ’   is a direction in which you can vary
the specification of an array's elements.
Ú An array that holds the sales total for each day of
the month has one dimension (the day of the
month).
Ú An array that holds the sales total by department
for each day of the month has two dimensions (the
department number and the day of the month).
Ú The number of dimensions an array has is called
its p .
Ú iou specify an element of an array by supplying
an ’ or  
p for each of its dimensions.
Ú The elements are contiguous along each
dimension from index 0 through the highest index
for that dimension.
Ú The following illustrations show the conceptual
structure of arrays with different ranks.
Ú Many arrays have only one dimension, such as the number of
people of each age.
Ú The only requirement to specify an element is the age for which
that element holds the count.
Ú Therefore, such an array uses only one index.
Ú The following example declares a variable to hold a 
’    pp  of age counts for ages 0 through 120.

Ú 
 

 
Ú Õome arrays have two dimensions, such as the number of
offices on each floor of each building on a campus.
Ú The specification of an element requires both the building
number and the floor, and each element holds the count for
that combination of building and floor.

Ú 
 


m 
{ 40 buildings and 5 floors in each building! }
ÚÕuppose we want to store total marks of 50
students of one class, we can use 1-D array as ::
Dim tot_marks(50) as double

ÚAnd if we want to store marks of all 50 students in


5 different subjects, we need to use 2-D array as
..
Dim stud_marks(50,5) as double
Ú A few arrays have three dimensions, such as values in
three-dimensional space.
Ú Õuch an array uses three indexes, which in this case
represent the , , nd  coordinates of physical space.
Ú The following example declares a variable to hold
a p ’    pp  of air temperatures at various
points in a three-dimensional volume.


  !  ""
""


 
Ú Lets discuss an application which assigns values
to 1-D array and prints its values to a list box «
Dim newarray(10) As Integer

d 

 
uor i = 0 To 9
newarray(i) = i + 1
Next i
MsgBox "values assigned successfully to NEWARRAi",
vbInformation, "result"




d 

 
uor i = 0 To 9
list1.AddItem (newarray(i))
Next i


Ú Õ RTING u 1-D ARRAi «.
Dim newarray(10) As Integer    
Dim n As Integer
Dim i, j, temp As Integer

d 

 
n = list1.ListCount 

 

 
#
 $



% 
 &  
$
'()
* +


#
 $



% 
#
,
$
 -



% 
.
 &  
/
 &  ,
 
 !
$
 &    
 &  
$
 &  ,
 &  ,
$
 !

.
* +
,
* +
.

#
 $



%  
  
&


)()
$
 &  
* +




Ú MATRIX ERATI NÕ..

ADD

ÕBTRACT

MLTILi





0


. 

 
 

. 

d 

# ) 
count1 = 0
count2 = 4
uor i = 0 To 1
uor j = 0 To 1
mat1(i, j) = count1
mat2(i, j) = count2
count1 = count1 + 1
count2 = count2 - 1
Next j
Next i

uor i = 0 To 1
uor j = 0 To 1
List1.AddItem mat1(i, j)
List2.AddItem mat2(i, j)

Next j
Next I



rivate Õub Command1_Click()
uor i = 0 To 1
uor j = 0 To 1
mat3(i, j) = mat1(i, j) + mat2(i, j)
List3.AddItem mat3(i, j)

Next j
Next i
End Õub
rivate Õub Command3_Click()
uor i = 0 To 1
uor j = 0 To 1
mat3(i, j) = mat1(i, j) - mat2(i, j)
List3.AddItem mat3(i, j)

Next j
Next i
End Õub
d 

 

uor i = 0 To 1

uor j = 0 To 1
mat3(i, j) = 0
uor k = 0 To 1
mat3(i, j) = mat3(i, j) + (mat1(i, k) * mat2(k, j))

Next k
List3.AddItem mat3(i, j)
Next j
Next i



G D DAi !!

You might also like