Working with Arrays

An array is a series of variables, each identified by the same name but a different index number. Arrays make it very easy for a program to process sets of related variables. Suppose, for example, you wanted to accumulate totals by month. To declare all twelve variables—one for each month—you could code:

Dim decMonTot(11) As Decimal

This reserves memory for 12 numbers of type Decimal. To access the total for January, you would code decMonTot(0). The total for February would be in decMonTot(1) and so forth. If you try access a subscript that doesn’t exist (outside the range 0–11 in this case) the program will fail.

Lingo

The word subscript means the numeric index of an array. If you specify a subscript larger than the array’s allocated ...

Get Faster Smarter Beginning Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.