UDF optional argument does not accept default value

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

UDF optional argument does not accept default value
 
Ronald Bouras




Posts: 32
Joined: 2006-05-20
Hi AddInExpress team,

I have a UDF with signature i.e.
DoSomething(string language = "DE")
.
In case I leave the argument out (when calling the function from a Excel cell) no default value is passed to my function.

According to https://www.add-in-express.com/forum/read.php?FID=5&TID=4006 I modified the signature to
DoSomething([Optional, DefaultParameterValue("DE")] string language)


Still no default value is passed to the function.

Does AddIn Express suppress the defaults when calling the UDF?

Any help appreciated,
thank you in advance, regards

Ron
Posted 24 Jun, 2015 02:01:15 Top
Andrei Smolin


Add-in Express team


Posts: 18847
Joined: 2006-05-11
Hello Ron,

Please check that topic: we demonstrate how to assign a default value in a UDF.


Andrei Smolin
Add-in Express Team Leader
Posted 24 Jun, 2015 04:34:19 Top
Ronald Bouras




Posts: 32
Joined: 2006-05-20
Hi Andrej,

where can I find this topic?

Regards
Ron
Posted 24 Jun, 2015 05:44:02 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hello Ron,

Andrei mentioned the topic that you provided in your original post:
https://www.add-in-express.com/forum/read.php?FID=5&TID=4006

You can use the Optional attribute but need to handle the missing parameter in your code:

DoSomething([System.Runtime.InteropServices.Optional] object language)
{
    if (language is System.Reflection.Missing)
    {
        language = "DE";
    }
    // ...
}
Posted 24 Jun, 2015 09:40:22 Top