20 Arrays

20.1 One-dimensional arrays

Suppose we need to store the name of a student in our program. No problem, we’ll use a variable of type String. But what if we need to save the names of 30 students? Should we use 30 variables of type String? Well, we could, but there is a better way. We can declare an array. An array can be regarded simply as a table with room for a number of data items, all of the same type. In the case at hand we would need an array with room for 30 names of type String. Each name in the array is called an array element. To declare such a structure we write:

Dim students(30) As String

It is almost like a simple variable declaration with the exception of the parentheses after the variable name. What we are saying here ...

Get Financial Modelling and Asset Valuation with Excel now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.