Although you usually set the number of elements in an array when you declare it, it's possible to alter the size of the array. When you change the number of elements in an existing array, you redimension it. To do so, use the ReDim keyword in the following syntax:
ReDim [Preserve] ArrayName(Subscript) As DataType
In this syntax,
Using ReDim in your codeThe actual implementation of the ReDim statement is different from this conceptual illustration. If you create an array that you'll later redimension, you can't hard code the element size of the array when you first declare it.
The following code shows how, conceptually, to redimension the array newArray
ReDim Preserve newArray(9) newArray(9) = 23
To create an array that you'll later resize, you must first create the array without any elements.
So far, we have studied one-dimensional arrays--that is, they are a one-row collection of variables such a row of students. In Visual Basic, however, you can create arrays that have up to 60 dimensions. Usually, two-dimensional arrays will suffice for most introductory programming projects, and most likely you won't need to make an array of more than three dimensions. The higher dimension arrays are required in scientific calculations such as space research and weather forecasting
Think of a two-dimensional array as a tic-tac-toe board--a set of columns and rows that intersect to form a grid. Each grid cell has a location defined by a
Go To Page: 1 2