Creates a one-dimensional or two-dimensional array of variables.

NoteNote

DIMENSION is identical in operation and similar in syntax to the DECLARE command. For more information, see DECLARE Command.

DIMENSION ArrayName1(nRows1 [, nColumns1]) [AS cType]
   [, ArrayName2(nRows2 [, nColumns2])] ...

Parameters

ArrayName1

Specifies the name of the array.

NoteTip

You can create multiple arrays with a single DIMENSION command by including additional array names, for example, ArrayName2, ArrayName3, and so on.

nRows1 [, nColumns1]

Specifies the size of the array to create.

NoteNote

You must specify a size for each array you create with DIMENSION. Array sizes can be limited by available memory, which affects performance, especially for very large arrays. Make sure your computer has enough memory to accommodate the upper limits of your arrays.

To create a one-dimensional array, include only nRows1. In this scenario, DIMENSION uses nRows1 to create the number of rows in a one-dimensional array with a single column. For example, the following command creates a one-dimensional array named gaArrayOne that contains ten rows and one column:

 CopyCode imageCopy Code
DIMENSION gaArrayOne(10)

To create a two-dimensional array, include both nRows1 and nColumns1. In this scenario, nRows1 specifies the number of rows in the array, and nColumns1 specifies the number of columns. The following example creates a two-dimensional array named gaArrayTwo containing two rows and four columns:

 CopyCode imageCopy Code
DIMENSION gaArrayTwo(2,4)
AS cType

Specifies a data type for the array. Using the AS  cType clause, you can define and specify a data type other than Variant for arrays. The AS  cType syntax does not appear in IntelliSense during design time; it is meant for use only at run time. For an example, see Example 4 in the Example section.

The AS  cType clause applies only when passing an array to a COM component. Otherwise, Visual FoxPro disregards the AS  cType clause. If you specify a data type that is not a valid COM data type, Visual FoxPro automatically defaults to VARIANT type. Data specified as VARIANT can only be passed by reference and not by strongly typed values.

The following table lists valid COM type mappings.

VFP defined type IntelliSense Quick Info COM friendly name COM Typelib .NET system type XSD (SOAP) type

Boolean

Logical

Boolean

VARIANT_BOOL (VT_BOOL)

System.Boolean

boolean

Byte

Number

Byte

unsigned char (VT_UI1)

System.Byte

 

Character *

String

String

BSTR (VT_BSTR)

System.String

string

Currency *

Currency

Currency

CURRENCY (VT_CY)

 

 

Date

Date

Date

DATE (VT_DATE)

System.DateTime

dateTime

DateTime

Date

Date

DATE (VT_DATE)

System.DateTime

dateTime

Decimal *

Number

 

wchar_t (VT_DECIMAL)

System.UInt16

 

Double

Number

Double

double (VT_R8)

System.Double

double

Float

 

Variant

VARIANT (VT_VARIANT)

System.Object

anyType

Integer

Number

Long

long (VT_I4)

System.Int32

int

Logical

Logical

Boolean

VARIANT_BOOL (VT_BOOL)

System.Boolean

boolean

Long

Number

Long

long (VT_I4)

System.Int32

int

Memo

 

Variant

VARIANT (VT_VARIANT)

System.Object

anyType

Number

Number

Double

double (VT_R8)

System.Double

double

Object

Object

Object

IDispatch* (VT_DISPATCH)

System.Object

 

Short

Number

Long

long (VT_I4)

System.Int32

int

Single *

Number

Single

single (VT_R4)

System.Single

 

String

String

String

BSTR (VT_BSTR)

System.String

string

Variant

 

Variant

VARIANT (VT_VARIANT)

System.Object

anyType

Void

VOID

Void

void (VT_VOID)

System.IntPtr

 

Array

Array

 

SAFEARRAY(type)

Type[]

Base64Binary

Expand imageRemarks

Expand imageExample

Expand imageSee Also