XLL+ Class Library (7.0)

Reading an optional argument

The source code has now been modified.

CXlOper* HISTVOL_Impl(CXlOper& xloResult, const CXlOper* Prices_op, const 
    CXlOper* DaysPerYear_op)
    // Input buffers 
    std::vector<double> Prices;
    double DaysPerYear; 
    // Validate and translate inputs
    XlReadVector(*Prices_op, Prices, L"Prices", XLA_TRUNC_ONEMPTY|
    XlReadScalar(*DaysPerYear_op, DaysPerYear, L"DaysPerYear", 
    XLA_DEFAULT_EMPTY, 250.0);                                 
    // End of generated code 
        xloResult = CalcHistVol(Prices, DaysPerYear);
    catch(const char*)
        xloResult = xlerrNum;
    return xloResult.Ret();
  1. The argument type DaysPerYear has changed type (to const CXlOper*) and name (to DaysPerYear_op).
  2. A new local variable double DaysPerYear, has been declared.
  3. Some lines have been generated to populate DaysPerYear from DaysPerYear_op.

All the work is done by XlReadScalar, using the value (250.0) that we specified in the Function Wizard.

There is no need to change your code; the Function Wizard's changes will do all the work.

This technique can also be used to read in optional boolean, integer and string values, or for values of any type, including extended types.

Next: More on optional arguments >>