|
|
Changing the Number of Elements in an ArrayAlthough 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 code 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. Multidimensional ArraysSo 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
The copyright of the article Arrays II in Learning Visual Basic is owned by . Permission to republish Arrays II in print or online must be granted by the author in writing.
|
|
|
|
|
|
|
|