VBScript: Multidimensional Arrays, Statements, and Commenting
(Page 1 of 6 )
We left off discussing variables and arrays in our last tutorial. I hinted at the existence of the mighty multi-dimensional array, but ran out of time before I could discuss this beast. However now I have an entire article to fill, so prepare to be amazed...multidimensionally.
In VBScript you can create arrays with up to sixty dimensions. You'll probably never need to, but you know there is some nerd out there trying to pick up chicks by bragging about how he once created a 60 dimensional array that held every ancillary character from the Phantom Menace. I mean there are those people that build log cabins out of toothpicks to ensure they are remembered after passing over to the dark abyss.
Its far easier to show you how to use multidimensional arrays than to explain them, and since I am a lazy writer, that is exactly what I am going to do:
<html>
<body>
<script type="text/vbscript">
Dim cow(3,2)
cow(0,0) = "Mister Moo "
cow(0,1) = "Moo McGoo "
cow(0,2) = "Bessie "
cow(0,3) = "Elmer"
</script>
</body>
</html>
In the above example we create a multidimensional array, specifically, a two-dimensional one. You will notice that cow(3,2) has two numbers separated by a comma. This is because multidimensional arrays work similar to a grid or a spreadsheet, with the first number representing a row and the second number representing a column. So for instance, in the above code, Bessie appears in row 0 of column 2. You perform actions on multidimensional arrays the same as you would any other array.
Next: Dynamic Arrays >>
More BrainDump Articles
More By James Payne