3. Exploring the Visual Basic Toolbox
Arrays
- Up to now, we've only worked with regular variables, each having
its own unique name. Visual Basic has powerful facilities for handling
multi-dimensional variables, or arrays. For now, we'll only use
single, fixed-dimension arrays.
- Arrays are declared in a manner identical to that used for regular
variables. For example, to declare an integer array named 'Items',
with dimension 9, at the procedure level, we use:
If we want the array variables to retain their value upon leaving a
procedure, we use the keyword Static:
Static Items(9) as Integer
At the form or module level, in the general declarations
area of the Code window, use:
And, at the module level, for a global declaration, use:
Global Items(9) as Integer
- The index on an array variable begins at 0 and ends at the dimensioned
value. For example, the Items array in the above examples has
ten elements, ranging from Items(0) to Items(9). You use array
variables just like any other variable - just remember to include its name
and its index. For example, to set Item(5) equal to 7, you simply write:
Counter Hit
This Homepage is special brought to you by CK Tan