vectorbase::GetDataAsOneDimensionalArray

Description

Return a copy of a vector or Dataset as a one dimensional array of type _VARIANT. GetDataAsOneDimensionalArray is a long name that is not as friendly, GetAs1DArray method is its simple version.

Syntax

_VARIANT GetDataAsOneDimensionalArray( int lowerBound = 0 )

Parameters

lowerBound
[input]The lowest index value in the array (default is 0)

Return

Returns a one dimensional array of type _VARIANT containg a copy of the data in a vector or Dataset.

Examples

EX1

#include <variant.h>

void vectorbase_GetDataAsOneDimensionalArray_ex1()
{
    // Declare a vector and fill with some data
    vector<float> vec;
    vec.SetSize(360);
    for( int ii=0; ii < 360; ii++ )
        vec[ii] = sin(2* ii * PI / 360.0);
    // Get the data from the vector into an 1-dimensional _VARIANT object
    _VARIANT varYData;
    varYData = vec.GetDataAsOneDimensionalArray();

    //Output the _VARIANT size
    out_int("size is ", varYData.GetSize());
}

Remark

When 1-dimensional objects such a vector or a Dataset is assigned to a COM object of type _VARIANT, a 2-dimensional array is created where the second dimension is set to 1. This is because applications such as Excel expect a 2-dimensional object such as when when assigning a _VARIANT to a range object.

However, some COM objects require 1-dimensional arrays of type _VARIANT. This function returns a 1-dimensional array from a vector or a Dataset.

_VARIANT is a universal type that exists in COM to hold various types of data. It is used to get the values of properties of COM objects. It can represent individual values of int, double, etc., as well as arrays and other composite types.

See Also

vectorbase::GetAs1DArray, vectorbase::GetAs2DArray

header to Include

origin.h, variant.h