Microsoft.VisualBasic.Financial.IRR - Error in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smlemmon
    New Member
    • Apr 2008
    • 1

    Microsoft.VisualBasic.Financial.IRR - Error in C#

    Hi,

    This is my first post, but have been an avid reader up until to now. Great resource though.

    Anyway, onto my problem.

    I need to use the Microsoft.Visua lBasic.Financia l.IRR procedure in my C# / ASP.NET 2.0 application.

    The code I am using is shown below:-

    Code:
    Decimal monthlyROI = 0;
    Decimal ROI = 0;
    Double estimate = 0.1;
    Double[] irrArray;
    ArrayList irrArrayList = new ArrayList();
    
    irrArrayList.Add((Double)Decimal.Negate(amountOfCredit));
    
    for (int termLoop = 0; termLoop < (term - 2); termLoop++)
    {
         irrArrayList.Add((Double)standardFinancePayment);
    }
    
     irrArrayList.Add((Double)Decimal.Add(monthlyFinancePayment, finalPayment));
    
    irrArray = (Double[])irrArrayList.ToArray(typeof(Double));
    
    monthlyROI = (Decimal)Microsoft.VisualBasic.Financial.IRR(ref irrArray, estimate);
    
    ROI = Decimal.Multiply(monthlyROI, 12);
    
    return ROI;
    When I run this peice of code, the call to Microsoft.Visua lBasic.Financia l.IRR raises an exception, "Arguments Are Not Valid".

    I thought it might have been to do with using the array list, and then populating the array with the contents of it.

    I tried just using a standard Double Array and then assigning its size when it was instantiated. THis too didnt work.

    The only way I can get this function to work correctly is by instantiating the array with values at design time as follows:-

    Code:
    Double[] irrArray = {-22500.00, 770, 770, 600, 500, 7770, 666,555,444,666,666};
    I am sure I am missing something really simple here and any guidance would be really appreciated.

    Regards

    Simon
Working...