XLL+ Class Library

CXlOper::FromNumericVector() Example

// Function:    IntArray
// Purpose:     Returns an integer array

//{{XLP_SRC(IntArray)
    // NOTE - the FunctionWizard will add and remove mapping code here.
    //    DO NOT EDIT what you see in these blocks of generated code!
IMPLEMENT_XLLFN2(IntArray, "RH", "IntArray", "Type", "User Define"
    "d", "Returns an integer array", "Integer type: 0=short;1=USH"
    "ORT;2=int;3=unsigned int;4=long;5=unsigned long\000", 
    "\0appscope=1\0", 1)

extern "C" __declspec( dllexport )
LPXLOPER IntArray(USHORT Type)
{
    XLL_FIX_STATE;
    CXlOper xloResult;
//}}XLP_SRC

    switch (Type)
    {
    case 0:
        {
            std::vector<short> v;
            for (short i = -5; i < 5; i++)
                v.push_back(i);
            xloResult.FromNumericVector(v);
        }
        break;
    case 1:
        {
            std::vector<USHORT> v;
            for (USHORT i = 0; i < 10; i++)
                v.push_back(i);
            xloResult.FromNumericVector(v);
        }
        break;
    case 2:
        {
            std::vector<int> v;
            for (int i = -5; i < 5; i++)
                v.push_back(i);
            xloResult.FromNumericVector(v);
        }
        break;
    case 3:
        {
            std::vector<unsigned int> v;
            for (unsigned int i = 0; i < 10; i++)
                v.push_back(i);
            xloResult.FromNumericVector(v);
        }
        break;
    case 4:
        {
            std::vector<long> v;
            for (long i = -5; i < 5; i++)
                v.push_back(i);
            xloResult.FromNumericVector(v);
        }
        break;
    case 5:
        {
            std::vector<unsigned long> v;
            for (unsigned long i = 0; i < 10; i++)
                v.push_back(i);
            xloResult.FromNumericVector(v);
        }
        break;
    default:
        CXlOper::RetString("#ERROR: Unknown type");
        break;
    }
    return xloResult.Ret();
}

Uses

CXlOper::FromNumericVector