Page 171 - Open Soource Technologies 304.indd
P. 171
Kumar Vishal, Lovely Professional University Unit 7: Arrays in Visual Basic
Unit 7: Arrays in Visual Basic
CONTENTS
Objectives
Introduction
7.1 Declaring Arrays
7.1.1 Fixed-sized Arrays
7.1.2 Multidimensional Arrays
7.1.3 Static and Dynamic Arrays
7.1.4 Arrays within UDTs
7.2 ReDim and Preserve Function
7.2.1 Using an Array as a Frequency
7.3 Control Array
7.3.1 Iterating on the Items of a Control Array
7.4 Summary
7.5 Keywords
7.6 Self Assessment Questions
7.7 Review Questions
7.8 Further Readings
Objectives
After studying this unit, you will be able to:
• Discuss declaring arrays
• Explain ReDim and Preserve function
• Understand the control array is visual basic
Introduction
By definition, an array is a list of variables, all with the same data type and name. When we
work with a single item, we only need to use one variable. However, if we have a list of items
which are of similar type to deal with, we need to declare and array of variables instead of using
a variable for each item. For example, if we need to enter one hundred names, we might have
difficulty in declaring 100 different names, this is a waste of time and efforts. So, instead of
declaring one hundred different variables, we need to declare only one array. We differentiate
each item in the array by using subscript, the index value of each item, for example name(1),
name(2), name(3)… etc., which will make declaring variables streamline and much systematic.
LOVELY PROFESSIONAL UNIVERSITY 165