Excel Automation Addin Problem with ParamArray param

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

Excel Automation Addin Problem with ParamArray param
Public Function MyUDF(ByVal ParamArray myTargetArray() As Object) 
Javier Amat




Posts: 2
Joined: 2007-06-20
Hi,
I created a class with several UDF that works perfectly.

But now, i needed to pass several values to a function where the number of arguments are unknown.

How can i get an unknown number of parameters from the excel formula?

In VBA works perfect, i think the problem us because in vba the paramarray works by reference and in .net it woul only work by value.

Any suggestion ?

Thanks,

Javier Amat
Posted 20 Jun, 2007 14:58:58 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Javier.

You can use the code below to define UDF with variable number of parameters.
public object MyFunc(params object[] values)
{
return "OK";
}

However, as far as I know it works in Excel 2007 only.
For earlier Excel versions I would suggest you to use the following signatures:

public object MyFunc(
[DefaultParameterValue(null)] object param1,
[DefaultParameterValue(null)] object param2,
[DefaultParameterValue(null)] object param3,
[DefaultParameterValue(null)] object param4,
[DefaultParameterValue(null)] object param5,
[DefaultParameterValue(null)] object param6,
......
[DefaultParameterValue(null)] object paramN
)
{
return "OK";
}

public object MyFunc1(
[Optional] object param1,
[Optional] object param2,
[Optional] object param3,
[Optional] object param4,
[Optional] object param5,
.......
[Optional] object paramN
)
{
return "OK";
}
Posted 21 Jun, 2007 11:37:45 Top
nitin c




Posts: 79
Joined: 2007-05-18
Thanks for the code Sergey.
Now I have overloaded UDFs !!!
Posted 25 Jun, 2007 05:51:14 Top
Javier Amat




Posts: 2
Joined: 2007-06-20
Thanks Sergey
Posted 27 Jun, 2007 06:17:07 Top