ProgrammerGuide.Net | Step by Step Programmer Guide

VB-Array

Array,

Erase statement
Reinitializes the elements of fixed-size arrays and releases dynamic-array storage space
Syntax: Erase arraylist
The required arraylist argument is one or more comma-delimited array variables to be erased.

Remarks
Erase behaves differently depending on whether an array is fixed-size (ordinary) or dynamic. Erase recovers no memory for fixed-size arrays. Erase sets the elements of a fixed array as follows:

Type of ArrayEffect of Erase on Fixed-Array Elements
Fixed numeric arraySets each element to zero.
Fixed string array (variable length)Sets each element to a zero-length string (“”).
Fixed string array (fixed length)Sets each element to zero.
Fixed Variant arraySets each element to Empty.
Array of user-defined typesSets each element as if it were a separate variable.
Array of objectsSets each element to the special value Nothing.

Example:
Erase sMessage
In a regular array, the Erase statement will simply initialize all the elements. (False for Boolean, 0 for numbers, and “” for strings). In a dynamic array, Erase will also release all the memory allocated to the array.

Dim
Dim statement placed right in the procedure where it’s going to be used. The value of a procedure level variable cannot be accessed outside it’s procedure. When the procedure finishes (End Sub or End Function), the variable is destroyed and memory allocated to the variable is released.
Example:
Dim Word As String.
ReDim
Used at procedure level to reallocate storage space for dynamic array variables.
Syntax: ReDim [Preserve] varname(subscripts) [As type] [, varname(subscripts) [As type]] . . .

The ReDim statement syntax has these parts:

PartDescription
PreserveOptional. Keyword used to preserve the data in an existing array when you change the size of the last dimension.
varnameRequired. Name of the variable; follows standard variable naming conventions.
subscriptsRequired. Dimensions of an array variable; up to 60 multiple dimensions may be declared. The subscripts argument uses the following syntax: [lower To] upper [, [lower To] upper]. When not explicitly stated in lower, the lower bound of an array is controlled by the Option Base statement. The lower bound is zero if no Option Base statement is present
typeOptional. Data type of the variable; may be Byte, Boolean, Integer, Long, Currency, Single, Double, Decimal (not currently supported), Date, String (for variable-length strings), String * length (for fixed-length strings), Object, Variant, a user-defined type, or an object type. Use a separate As type clause for each variable being defined. For a Variant containing an array, type describes the type of each element of the array, but doesn’t change the Variant to some other type.

Remarks
The ReDim statement is used to size or resize a dynamic array that has already been formally declared using a Private, Public, or Dim statement with empty parentheses (without dimension subscripts).

Example:
Dim X(10, 10, 10)
[Code]
ReDim Preserve X(10, 10, 15)

Please click here for related products on Amazon!

Jayashee

Add comment

Want to Check Celebrities News?