Returning Error in automation function a‌ddin

Add-in Express™ Support Service
That's what is more important than anything else

Returning Error in automation function a‌ddin
 
Xavier N


Guest


Hello,
I've got a mixed xll+com adx addin. Some of the function are based on automation technology. Under certain circonstance, i want to return an error value for these function. So i tried the ADXxlCVError enumeration to do so - as recommended by adx, but the function return the underlying integer value of the enum (eg 2015 for ADXxlCVError.xlErrValue, 2042 for xlErrNA) and not #VALUE localized upon the user language settings... (In Xll function the enumeration ADXExcelError return correctly the #VALUE localized ADXExcelError.xlErrorValue)..
It's quite a big problem for calculation...
Is this a known issue ? Any idea to solve this. Thanks a lot for your solution/investigation.
Regards. Xavier
Posted 01 Dec, 2016 08:39:57 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Xavier,

The following function returns #DIV/0! (as expected):

        internal static class XLLContainer
        {
            /// <summary>
            /// Required by Add-in Express. Please do not modify this method.
            /// </summary>
            internal static XLLModule Module
            {
                get
                {
                    return AddinExpress.MSO.ADXXLLModule.
                        CurrentInstance as MyXLLAddin13.XLLModule;
                }
            }

            public static object ATestFunction() {
                return AddinExpress.MSO.ADXExcelError.xlErrorDiv0;
            }
        }




Andrei Smolin
Add-in Express Team Leader
Posted 01 Dec, 2016 09:54:14 Top
Xavier N


Guest


Hello Andrei,
Thanks for your answser. It's also do for me in an xll. But i was not really clear in my issue : the problem is not with xll function but with automation function - in a com addin (or mixed xll/com addin). As said in https://www.add-in-express.com/docs/net-excel-udf-tips.php#error-value, i'm using ADXxlCVError enum. With your exemple function in an automation addin if i use ADXxlCVError.xlErrDiv0 it with return 2007 (If i use ADXExcelError.xlErrorDiv0 in my automation function, it return 7)...
Can your make a try ?
Thanks again. Regards. Xavier
Posted 01 Dec, 2016 10:59:21 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Xavier,

That was a mistake in the manual; the correct way of returning an error from an Excel automation add-in is this:

public object MyFunc() {
    return CVErr(AddinExpress.MSO.ADXxlCVError.xlErrNull);
}


I'm sorry for the trouble this issue may have caused you.

Note the terminology:
COM add-in: ADXAddinModule
XLL add-in: ADXXllModule
Excel Automation add-in: ADXExcelAddinModule


Andrei Smolin
Add-in Express Team Leader
Posted 02 Dec, 2016 07:48:44 Top
Xavier N


Guest


Hello Andrei,

Thanks you very much, it works well..
(As some of the functions are not located in the ADXExcelAddinModule, i have no access at first time at CVErr. Just created a public variable referencing the instance of the module in the _initialize event and then i use CVErr method from that instance..)

Thanks again Andrei.
Regards. Xavier
Posted 02 Dec, 2016 08:56:49 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 02 Dec, 2016 09:25:06 Top