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

double[] values = new double[73];
            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

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[73];
#
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.Control.onload(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
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:[73]} double[]
[0] -62881732.0 double
[1] 379525.0 double
[2] 379525.0 double
[3] 379525.0 double
[4] 379525.0 double
[5] 379525.0 double
[6] 379525.0 double
[7] 379525.0 double
[8] 379525.0 double
[9] 379525.0 double
[10] 379525.0 double
[11] 379525.0 double
[12] 379525.0 double
[13] 421360.875 double
[14] 421360.875 double
[15] 421360.875 double
[16] 421360.875 double
[17] 421360.875 double
[18] 421360.875 double
[19] 421360.875 double
[20] 421360.875 double
[21] 421360.875 double
[22] 421360.875 double
[23] 421360.875 double
[24] 421360.875 double
[25] 455805.23625 double
[26] 455805.23625 double
[27] 455805.23625 double
[28] 455805.23625 double
[29] 455805.23625 double
[30] 455805.23625 double
[31] 455805.23625 double
[32] 455805.23625 double
[33] 455805.23625 double
[34] 455805.23625 double
[35] 455805.23625 double
[36] 455805.23625 double
[37] 493056.6307875 double
[38] 493056.6307875 double
[39] 493056.6307875 double
[40] 493056.6307875 double
[41] 493056.6307875 double
[42] 493056.6307875 double
[43] 493056.6307875 double
[44] 493056.6307875 double
[45] 493056.6307875 double
[46] 493056.6307875 double
[47] 493056.6307875 double
[48] 493056.6307875 double
[49] 533343.225182625 double
[50] 533343.225182625 double
[51] 533343.225182625 double
[52] 533343.225182625 double
[53] 533343.225182625 double
[54] 533343.225182625 double
[55] 533343.225182625 double
[56] 533343.225182625 double
[57] 533343.225182625 double
[58] 533343.225182625 double
[59] 533343.225182625 double
[60] 533343.225182625 double
[61] 576911.69160460879 double
[62] 576911.69160460879 double
[63] 576911.69160460879 double
[64] 576911.69160460879 double
[65] 576911.69160460879 double
[66] 576911.69160460879 double
[67] 576911.69160460879 double
[68] 576911.69160460879 double
[69] 576911.69160460879 double
[70] 576911.69160460879 double
[71] 576911.69160460879 double
[72] 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.

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, networking, learning, and sharing knowledge.