Link to home
Start Free TrialLog in
Avatar of Kadakal
Kadakal

asked on

How to pass multiple parameters to user defined function in excel

Hi Experts,

I am working on an Excel add-in and want to pass multiple parameter to a function which i defined.

for example if i send the parameters as follows it doesn't work.

  public int AddNumbers(params int[] Numbers)
        {
            int Result = 0;
            for (int i = 0; i < Numbers.Length; i++)
            {
                if (i==0)
                {
                    Result = Numbers[i];
                }
                else
                {
                   Result = Numbers[i - 1] + Numbers[i];
                }
               
            }
            return Result;
        }

but if i use the function as follows it works,

        public int Addtest(int a, int b){

            int test = 0;
            try
            {
                test = AddNumbers(new int[] {a,b });
            }
            catch (Exception)
            {
               
                throw;
            }
            return test;
        }

My question is, I have a user defined function in my excel add-in project  and want to pass last parameters as a parameter array not as an optional range.

public object DummyFunction(string strDummy1, string strDummy2, object objDummy, params string[] strInputs)

ASKER CERTIFIED SOLUTION
Avatar of chriswilsonuk
chriswilsonuk
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial