why is this code not working?

N

NA_AB

Why am I not able to invoke this function? all I get is the same old
"#VALUE!" when I'm calling it in the excel cell as =addnumbers(10) it is
working fine and returning me a '10' onto the cell. But when I say
=addnumbers(10,20) or =addnumbers(10,20,30), it gives me a "#VALUE!"


public double AddNumbers(double Number1, [Optional] object Number2,
[Optional] object Number3)
{
double result = 0;
result += Convert.ToDouble(Number1);

if (!(Number2 is System.Reflection.Missing))
{
Excel.Range r2 = Number2 as Excel.Range;
double d2 = Convert.ToDouble(r2.Value2);
result += d2;
}

if (!(Number3 is System.Reflection.Missing))
{
Excel.Range r3 = Number3 as Excel.Range;
double d3 = Convert.ToDouble(r3.Value2);
result += d3;
}

return result;
}


What could be the problem!?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top