Chapter 13

## Introduction

In the previous chapter, the list box controls demonstrated the use of index values. The index starts from 0 for the first item. The subsequent items have an index 1, 2, 3 and so on.

The indexed items in a list box provide a good analogy for the new concept you'll learn in this chapter: arrays. A list box is a control that contains indexed items whereas an array is a list of variables that contains indexed items. If a large amount of data is to stored, it would be long and tedious task to think of separate variable names, and then to type the declaration for each one of these variables. Arrays are the solution to this problem. In programming terminology, an array's index value is called subscript.

 An array is a group of elements that share a common name, and that are differentiated from one another by their positions within the array.

For those movie buffs who are fans of the old Charlie Chan detective movies, you will remember that whenever it became necessary for Mr. Chan to introduce his sons to clients, he would always introduce them as: "This is my number one son... my number two son...". It is clear from this that even though computers were a long way from being invented at the time those movies were made, Mr. Chan actually resorted to the method of introducing his sons by their subscripts.

 A subscript is the numeric index value of the elements in an array.

If we are interested in a large number of recorded Celsius temperatures, we can assign a common name such as C_temp to all of the data.

To make things even clearer, here is a fragment of the code used to add 50 separate variables together, which have different names:

intTotal = int1 + int2 + int3...................

The code that adds 50 elements from an array is shown below:

For intCounter = 0 To 49
intTotal = intTotal + intValues(intCounter)
Next intCounter

From the above code, the following things become clear:

• Array subscripts go inside parentheses after the array name.
• All elements of an array have the same data type.
• You can access any array element in any order by specifying its subscript.
• The subscript starts from 0.

All subscripts begin at 0 unless you insert the following statement in the module's Declaration section:

Option base 1