Array Function

Returns aVariant (Variant data type: The default data type for variables that don't have type-declaration characters when a Deftype statement isn't in effect. A Variant can store numeric, string, date/time, Null, or Empty data.) containing an array (array: A variable that contains a finite number of elements that have a common name and data type. Each element of an array is identified by a unique index number. Changes made to one element of an array don't affect the other elements.).

Syntax

Array(arglist)

The required arglist argument (argument: A value that provides information to an action, an event, a method, a property, a function, or a procedure.) is a comma-delimited list of values that are assigned to the elements of the array contained within the Variant. If no arguments are specified, an array of zero length is created.

Remarks

The notation used to refer to an element of an array consists of the variable (variable: A named storage location capable of containing data that can be modified during program execution. Each variable has a name that uniquely identifies it within its level of scope. A data type can be specified or not.) name followed by parentheses containing an index number indicating the desired element. In the following example, the first statement (statement: A syntactically complete unit that expresses one specific kind of operation, declaration, or definition. A statement is usually on one line in a procedure or Declarations section, but two or more can be on a line separated by a colon (:).) creates a variable named A as a Variant. The second statement assigns an array to variable A. The last statement assigns the value contained in the second array element to another variable.

 Note   Examples that follow demonstrate the use of this function in a Visual Basic for Applications (VBA) module. For more information about working with VBA, select Developer Reference in the drop-down list next to Search and enter one or more terms in the search box.

Dim A As Variant
A = 10,20,30
B = A(2)

The lower bound of an array created using the Array function is determined by the lower bound specified with the Option Base statement, unless Array is qualified with the name of the type library (for example VBA.Array). If qualified with the type-library name, Array is unaffected by Option Base.

 Note   A Variant that is not declared as an array can still contain an array. A Variant variable can contain an array of any type, except fixed-length strings and user-defined types (user-defined data type: In a Microsoft SQL Server database, a definition of the type of data a column can contain. It is defined by the user, and based on existing SQL Server data types. Rules and defaults can only be bound to user-defined data types.). Although a Variant containing an array is conceptually different from an array whose elements are of type Variant, the array elements are accessed in the same way.

Example

This example uses the Array function to return a Variant containing an array.

Dim MyWeek, MyDay
MyWeek = "Mon" "Tue" "Wed" "Thu" "Fri" "Sat" "Sun"
' Return values assume lower bound set to 1 (using Option Base
' statement).
MyDay = MyWeek(2)    ' MyDay contains "Tue".
MyDay = MyWeek(4)    ' MyDay contains "Thu".
 
 
Applies to:
Access 2007