All arrays in VB have to be declared. The declaration tells VB the name of the array, how many items it can store, and what sort of data it can store. If you declare the array in the general declarations section of a form, the array is visible to all procedures and functions in that form. If you declare the array as Public in a Module it will be visible to every procedure and function in your project. To declare an array use the following syntax:
Dim ArrayName(LowerValue To HigherValue) As DataType
Dim specifies the scope of the array. If you declare it in a Form, use Dim or Private, if you declare it in a Module and you want every procedure to access it, declare it as Public. If you declare the array in a procedure use Dim. ArrayName is the name of the array. LowerValue is the first element in the array. HigherValue is the last element in the array. DataType is a valid datatype (ie String)/ You don't have to specify the LowerValue, but if you don't, the array will start from 0. For example,
Dim sTestArray(0 To 10) As String
is the same as
Dim sTestArray(10) As String
The code below declares nArray, with 1 as the first element, 30 as the last element, all of which stores Integers.
Dim nArray( 1 To 30 ) As Integer
Comments