The VB 6 arrays hold data of a single type. In this article, you will learn about declaring, assigning, and various array handling techniques.
Types of VB 6 Array
You can divide VB 6 arrays into two sets –
One-dimensional array and .
Multi-dimensional arrays The VB 6 can have a maximum of 60 dimensions. The arrays in Vb 6 are also classified based on keywords used to declare them:
- Regular arrays – It is declared using keyword
Dimwhole values remain variable.
- Dynamic arrays – A standard array can be expanded for more space, hence, it is called dynamic array. You can use keyword –
ReDimto redeclare the array.
- Static arrays – A static variable does change its value after exiting a procedure in which they were declared. static arrays do the same and retain their value between procedure calls.
- Private arrays – The scope is limited to the procedure in which it is defined. Use the keyword –
Privateto define the procedure.
- Public arrays – The scope is an entire program or module. Use the keyword
Publicin the module.
- Type arrays – This is for user-defined array types
The regular arrays are the usual way of declaring an array using the
Dim statement. The syntax to declare a regular array is given below:
Dim [WithEvents] variable_name [(Subscripts)] [As [New] type] [, [WithEvents] variable2_name [(Subscripts)] [As [New] type] ...
- WithEvents – This is an optional parameter and it is required when the variable is an object-variable type. An object-variable is used in modules with class or class modules.
- Variable_name – It is the user-defined name of the variable.
- Subscripts – They are optional parameters. An integer value subscript value indicates the number of members in an array. There are two ways to declare subscript:
[lower To] upper
TotalAmount( 10 To 20)
- New – This is an optional parameter and required only when the variable is object-variable type.
- tpye- Defines the variable type which can be one of the following: Byte, Boolean, Currency, Long, Double, Single, String and Date.
Assigning Values to Regular Array Elements
To assign values to array elements refer to them using an index and then assign value like any normal variable.