| << 4.8.1- Declaring Arrays | Chapter4 | 4.9.0- Summary >> |
Multi-Dimensional Arrays
If you need to keep information of a two-dimensional nature, then you can do it by declaring a two-dimensionalarray. For instance, if you wanted to store a set of related informationseparately such as a first and last name, a normal array would probably beunsuitable. Instead, you achieve it by adding another parameter to your arraydeclaration. Thus:
Dim str2Darray(3,3)
Would set up a two-dimensional array of size 4 by 4, whichcould hold a total of 16 values. You can assign values to a multi-dimensionalarray by referencing each element of the array through its two-value index. Forexample, you could use such an array to store first and last names and phonenumber:
str2Darray(0,0) = "John"
str2Darray(1,0) = "Doe"
str2Darray(2,0) = "111-111-1111"
str2Darray(0,1) = "Jane"
str2Darray(1,1) = "Doe"
str2Darray(2,1) = "222-222-2222"
The first dimension stores the information that is relatedto one person, such as first, last name and phone number, while the seconddimension holds data of the same type for different people, such as a set ofphone numbers. In fact, VBScript is not limited to arrays of one or twodimensions; you can declare an array with up to 60 dimensions, should you sorequire. However using anything more than three dimensions is impractical andyou'd be better off pursuing other solutions such as databases if you requiremore than three. This takes us as far as we need to go with arrays andvariables, we'll be using them throughout the rest of this book, so take careto understand them.
| << 4.8.1- Declaring Arrays | Chapter4 | 4.9.0- Summary >> |

RSS

