DADiSP Worksheet Functions > Function Categories > ActiveX > Automation Client > CASTVARIANTARRAY
Explicitly converts a series to an array of variants for Automation.
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 |
1 |
nothing |
VT_EMPTY |
2 |
2 byte integer |
VT_I2 |
3 |
4 byte integer |
VT_I4 |
4 |
4 byte float |
VT_R4 |
5 |
8 byte double |
VT_R8 |
6 |
currency |
VT_CY |
7 |
date |
VT_DATE |
8 |
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 |
The series. The series is marked so that it is converted to an array of variants when used with ActiveX Automation.
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.
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.