This example uses CXlOper::IsVector(), CXlOper::GetVectorCount() and CXlOper::VectorCell() to iterate the cells in a CXlOper 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_XLLFN3(VectorSum, VectorSum_4, VectorSum_12, "RP", "UQ", L"VectorSum", 0, L"Input", 0, L"Demo functions", 0, L"Returns the sum of a vector", 0, L"Input vector\0", 0, 0, L"{VectorSum,,,Returns the sum of a vector,Demo f" L"unctions,1,128,U,{{0,{Input,Value,0,,Input vector,,,,}}},{},3,,0,0}", 1) CXlOper* VectorSum_Impl(CXlOper&, const CXlOper*); extern "C" __declspec(dllexport) LPXLOPER12 VectorSum_12(LPXLOPER12 Input) { XLL_FIX_STATE; CXlOper xloResult, Input__port(Input); try { CXlStructuredExceptionHandler _seh_; xloResult.HandleResult(VectorSum_Impl(xloResult, &Input__port)); } catch(const CXlRuntimeException& ex) { CXllApp::Instance()->DisplayException(xloResult, ex); } return xloResult.Ret12(); } extern "C" __declspec(dllexport) LPXLOPER4 VectorSum_4(LPXLOPER4 Input) { XLL_FIX_STATE; CXlOper xloResult, Input__port(Input); try { CXlStructuredExceptionHandler _seh_; xloResult.HandleResult(VectorSum_Impl(xloResult, &Input__port)); } catch(const CXlRuntimeException& ex) { CXllApp::Instance()->DisplayException(xloResult, ex); } return xloResult.Ret4(); } CXlOper* VectorSum_Impl(CXlOper& xloResult, const CXlOper* Input) { // End of generated code //}}XLP_SRC BOOL bOk = TRUE; // This function doesn't work on 2-dimensional arrays // so return an error if ( !Input->IsVector() ) { xloResult = xlerrValue; return xloResult.Ret(); } // Iterate vector's cells, adding up // any numeric values USHORT i, cCells; double dSum = 0.0; cCells = (USHORT)Input->GetVectorCount(); for ( i = 0; i < cCells; i++ ) { if ( Input->VectorCell(i).IsDouble() ) dSum += (double)Input->VectorCell(i); } // Return the total xloResult = dSum; return xloResult.Ret(); }
CXlOper::VectorCell | CXlOper::IsVector | CXlOper::GetVectorCount