Hi I'm trying to use the Microsoft.VisualBasic IRR function, but to no success.

``````double[] values = new double;
for (int j = 1; j <= 73; j++)
{
values[j] = C158_Calc;
}

B162_Calc = Financial.IRR(values, 0.1) * 12;``````

I'm having trouble in this line:

``B162_Calc = Financial.IRR(values, 0.1) * 12;``

I'm not sure how to call the values

## All 9 Replies

``B162_Calc = Financial.IRR(ref values, 0.1) * 12; //<-- add ref``

Thanks,

I've figured out that the array is not getting the values.

``````#
double[] values = new double;
#
for (int i = 1; i <= 240; i++)
#
{
#
double BW154_Calc = 0.0;
#
if (i == 72)
#
BW154_Calc = (C152_Calc * 12 / G169_In) * 100;
#
if (i == 240)
#
BW154_Calc = (C152_Calc * 12 / G170_In) * 100;
#

#
num3 += BW154_Calc;
#

#
// calculate 6 year IRR
#
if (i == 1)

C158_Calc = H30_Out + C152_Calc;

if (i >= 2 && i <= 72)

C158_Calc = C152_Calc;
#
if (i == 73)
#
C158_Calc = C152_Calc + num3;

// total 6 year IRR
for (int j = 1; j == values.Length - 1; j++)
{

values[j] = C158_Calc;

}

// calculate 20 year IRR
double C160_Calc = 0.0;
if (i == 1)
C160_Calc = H30_Out + C152_Calc;
else
C160_Calc = C152_Calc;``````

Hey, this function is still not working:

Server Error in '/calculator2' Application.
Arguments are not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Arguments are not valid.

Source Error:

Line 166:
Line 167:
Line 168: B162_Calc = Financial.IRR(ref values, 0.1);
Line 169: row9["Month1"] = String.Format("{0:#,###,###,###.##}", B162_Calc);
Line 170:

Source File: e:\Inetpub\wwwroot\calculator2\irr.aspx.cs Line: 168

Stack Trace:

[ArgumentException: Arguments are not valid.]
Microsoft.VisualBasic.Financial.IRR(Double[]& ValueArray, Double Guess) +436484
irr.GetTable() in e:\Inetpub\wwwroot\calculator2\irr.aspx.cs:168
irr.Page_Load(Object sender, EventArgs e) in e:\Inetpub\wwwroot\calculator2\irr.aspx.cs:33
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

BreakPoint:
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

- values {Dimensions:} double[]
 -62881732.0 double
 379525.0 double
 379525.0 double
 379525.0 double
 379525.0 double
 379525.0 double
 379525.0 double
 379525.0 double
 379525.0 double
 379525.0 double
 379525.0 double
 379525.0 double
 379525.0 double
 421360.875 double
 421360.875 double
 421360.875 double
 421360.875 double
 421360.875 double
 421360.875 double
 421360.875 double
 421360.875 double
 421360.875 double
 421360.875 double
 421360.875 double
 421360.875 double
 455805.23625 double
 455805.23625 double
 455805.23625 double
 455805.23625 double
 455805.23625 double
 455805.23625 double
 455805.23625 double
 455805.23625 double
 455805.23625 double
 455805.23625 double
 455805.23625 double
 455805.23625 double
 493056.6307875 double
 493056.6307875 double
 493056.6307875 double
 493056.6307875 double
 493056.6307875 double
 493056.6307875 double
 493056.6307875 double
 493056.6307875 double
 493056.6307875 double
 493056.6307875 double
 493056.6307875 double
 493056.6307875 double
 533343.225182625 double
 533343.225182625 double
 533343.225182625 double
 533343.225182625 double
 533343.225182625 double
 533343.225182625 double
 533343.225182625 double
 533343.225182625 double
 533343.225182625 double
 533343.225182625 double
 533343.225182625 double
 533343.225182625 double
 576911.69160460879 double
 576911.69160460879 double
 576911.69160460879 double
 576911.69160460879 double
 576911.69160460879 double
 576911.69160460879 double
 576911.69160460879 double
 576911.69160460879 double
 576911.69160460879 double
 576911.69160460879 double
 576911.69160460879 double
 576911.69160460879 double

Try with a simple set of known data first. E.g:

``````double[] testvalues = new double[] { -100, 200, 300 };
B162_Calc = Financial.IRR(ref testvalues, 0.1);``````

Jip, that worked. Why won't my values?

Sorry, can't help you with that one. I have never used `Financial.IRR` Why not try testing with a small array of your values and see if the number of elements (or total value) is the problem.

Ok, thank you.

try this

B162_Calc = Financial.IRR(ref testvalues, 1);

try this

B162_Calc = Financial.IRR(ref testvalues, 1);

Thanks for the input but this thread is over a year old.
I think by now the original problem has probably been solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.