default argument value in AddInX

Jul 6, 2014 at 4:03 PM
Edited Jul 6, 2014 at 4:16 PM
I am trying to use some default values to my function. I know that someone posted earlier that a way to handle default arguments is to assume a LPOPER type.

However, I also noticed that in file args.h there is a member function
template<class T> XArgs& Arg(xcstr type, xcstr name, xcstr help, const T& t)
which assumes that it assigns a default value t to its argument,

Let's say I want to redesign the xll.sqrt function and assume the default input value is one if a user doesn't specify an argument value.

I tried to use
static AddInX xai_sqrt(
    FunctionX(XLL_LPXLOPERX, _T("?xll_sqrt"), _T("XLL.SQRT"))
    .Arg<double> (XLL_DOUBLEX, _T("num"), _T(" "), 1.0)
    .FunctionHelp(_T(" "))
    .Documentation(_T(" "))
and keep the same xll_sqrt routine.

In excel sheet, XLL.SQRT(4) returns 2. But XLL.SQRT() returns 0.
I am very new to this XLL programming. My question is how I can use above AddinX to make XLL.SQRT() take default value 1.

Jul 6, 2014 at 5:07 PM
Congratulations! You have found an unadvertised feature. See my latest blog post for the details:
Excel has it's own notion of default values. If an argument is missing, Excel will still provide you with something. For numbers you get 0, for strings you get "", and for OPER's you get xltypeMissing.