XLL+ Class Library

COper::VectorCell() Example

This example uses COper::IsVector(), COper::GetVectorCount() and COper::VectorCell() to iterate the cells in a COper argument containing a vector.

//{{XLP_SRC(VectorSum)
    // NOTE - the FunctionWizard will add and remove mapping code here.
    //    DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN2(VectorSum, "RP", "VectorSum", "Input", 
    "Demo functions", "Returns the sum of a vector", "Input vecto"
    "r\000", "\0", 1)

extern "C" __declspec( dllexport )
LPXLOPER VectorSum(const COper* lpopInput)
{
    CXlOper xloResult;
//}}XLP_SRC

    BOOL bOk = TRUE;

    // This function doesn't work on arrays
    // so return an error
    if ( !lpopInput->IsVector() )
    {
        xloResult = xlerrValue;
        return xloResult.Ret();
    }

    // Iterate vector's cells, adding up 
    // any numeric values
    USHORT i, cCells;
    double dSum = 0.0;
    cCells = (USHORT)lpopInput->GetVectorCount();
    for ( i = 0; i < cCells; i++ )
    {
        if ( lpopInput->VectorCell(i).IsDouble() )
            dSum += (double)lpopInput->VectorCell(i);
    }

    // Return the total
    xloResult = dSum;
    return xloResult.Ret();
}

Uses

COper::VectorCell | COper::IsVector | COper::GetVectorCount