CASTVARIANTARRAY

Purpose:

Explicitly converts a series to an array of variants for Automation.

Syntax:

CASTVARIANTARRAY(series, type)

series

-

A series or table.

type

-

Optional. An integer specifying the Variant array type. Defaults to 5 (double). Valid conversions are as follows:

 

Type

Description

VARTYPE

nothing

VT_EMPTY

2 byte integer

VT_I2

4 byte integer

VT_I4

4 byte float

VT_R4

8 byte double

VT_R8

currency

VT_CY

date

VT_DATE

binary string

VT_BSTR

10

error

VT_ERROR

11

boolean

VT_BOOL

12

variant

VT_VARIANT

13

unknown

VT_UNKNOWN

16

char

VT_I1

17

unsigned char

VT_UI1

18

unsigned short

VT_UI2

19

unsigned int

VT_UI4

20

8 byte integer

VT_I8

21

8 byte unsigned

VT_UI8

22

machine int

VT_INT

23

unsigned machine int

VT_UINT

24

void

VT_VOID

28

C-style array

VT_CARRAY

30

null-terminated string

VT_LPSTR

31

wide null-terminated string

VT_LPWSTR

 

Returns:

The series. The series is marked so that it is converted to an array of variants when used with ActiveX Automation.

Example:

a = 1..5;

xl = createobject("Excel.Application");

xl.workbooks.add();

xl.range("A1:A5").value = a;

xl.range("B1:B5").value = castvariantarray(a);

xl.range("C1:C5").value = castvariantarray(a, 2);

xl.visible = 1;

 

Starts Excel and creates a new workbook. The series in variable a is transferred to cells A1 through A5 as a normal array of doubles. The same series is converted to an array of variants where each variant contains a double. This converted series is placed in cells B1 through B5. The series is also converted to an array of variants where each variant contains a 2 byte integer. This converted series is placed in cells C1 through C5. Because Excel internally converts all these arrays in the same manner, the results are identical.

Remarks:

CASTVARIANTARRAY is helpful with ActiveX Automation when a series must be transferred as an array of variants instead of the normal array of doubles.

 

Not all variant types can be converted successfully for the array.

 

Use CASTVARIANT to convert a series to an array of almost any type supported by Automation.

See Also:

CREATEOBJECT

CASTVARIANT

GETDATA

GETVARIANTDATA

PUTDATA