Error in calculating irr in asp.net and vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asmasm1
    New Member
    • Aug 2008
    • 7

    Error in calculating irr in asp.net and vb.net

    i am calculating irr and pass listarray created at runtime to irr function and i get error. as i'm new to .net
    i have to calculate irr
    textbox2.text specify the no installments
    textbox1.text specify loan amount
    textbox5.text specify the amount of installments
    Dim i As Int16
    Dim pay As New ArrayList()
    For i = 0 To TextBox2.Text
    pay.Add(TextBox 5.Text)
    Next
    pay.Add(-TextBox1.Text)
    Dim ir As Double
    ir = Math.Round(Micr osoft.VisualBas ic.Financial.IR R(pay (TextBox2.Text + 1), 0.1), 2)
    TextBox7.Text = ir
    GET THIS ERROR MESSAGE
    Unable to cast object of type 'System.Double' to type 'System.Double[]'.
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    I think there is type mismatch in parameter types while calling the following function :

    ir = Math.Round(Micr osoft.VisualBas ic.Financial.IR R(pay (TextBox2.Text + 1), 0.1), 2).

    This is because the type of parameters in the function definition IRR must match the type of parameters passed to the function.
    Please check the return type and parameter type of function IRR in order to remove the error you are getting.

    Comment

    • asmasm1
      New Member
      • Aug 2008
      • 7

      #3
      thanks shweta123

      I think there is type mismatch in parameter types while calling the following function :

      ir = Math.Round(Micr osoft.VisualBas ic.Financial.IR R(pay (TextBox2.Text + 1), 0.1), 2).

      as i am passing arraylist (pay(15) as ist parameter and guess (0.1) as 2nd
      parameter the variable ir is taken as double
      as irr function will only return the value of irr which would be double

      Comment

      • shweta123
        Recognized Expert Contributor
        • Nov 2006
        • 692

        #4
        Hi,

        Following is the method for solving the error you are getting :

        1> Please see the function definition and check the parameters your function is accepting.
        2> Call the function with same types of parameters.
        3> If you are sending different types of parameters to the function then
        you can call the function by doing typecasting method.

        Originally posted by asmasm1
        thanks shweta123

        I think there is type mismatch in parameter types while calling the following function :

        ir = Math.Round(Micr osoft.VisualBas ic.Financial.IR R(pay (TextBox2.Text + 1), 0.1), 2).

        as i am passing arraylist (pay(15) as ist parameter and guess (0.1) as 2nd
        parameter the variable ir is taken as double
        as irr function will only return the value of irr which would be double

        Comment

        • asmasm1
          New Member
          • Aug 2008
          • 7

          #5
          Originally posted by shweta123
          Hi,

          Following is the method for solving the error you are getting :

          1> Please see the function definition and check the parameters your function is accepting.
          2> Call the function with same types of parameters.
          3> If you are sending different types of parameters to the function then
          you can call the function by doing typecasting method.
          hi shweta
          irr function returns value of irr which is of type double and the double variable is used to hold the value

          Comment

          • PRR
            Recognized Expert Contributor
            • Dec 2007
            • 750

            #6
            First and foremost you should use conversion of string for surety that your inputs are right....
            Convert.ToInt() or Convert.ToDoubl e();

            Code:
            int i;
                        ArrayList pay =new ArrayList();
                        // Better Option is 
                        List<int> pay1=new List<int>();
            
            //[B]For i = 0 To TextBox2.Text?? [/B]
                        // What exactly are you doin here?
                        //for(int 0;i<Convert.ToInt32(TextBox.Text);i++)//
            
            ir = //YOURFUNCTION(pay[index],0.1,2);
            //(pay (TextBox2.Text + 1), 0.1), 2)
            // what exactly are you passing in the function?

            Comment

            • asmasm1
              New Member
              • Aug 2008
              • 7

              #7
              thanx dirtbag

              I am developing application for loan purposes and i have to calculate irr
              textbox2.text specify the no installments
              those no equal installments are added to arraylist
              Code:
              //For i = 0 To TextBox2.Text?? 
                          // Add elements of array list
                          //for(int 0;i<Convert.ToInt32(TextBox.Text);i++)//
               
              ir = //YOURFUNCTION(pay[index],0.1,2);
              //(pay (TextBox2.Text + 1), 0.1), 2)
              // what exactly are you passing in the function?
              passing arraylist (pay(x) as ist parameter and guess (0.1)
              as i have also mentioned whole problem in my posts
              thanks again for response

              Comment

              • PRR
                Recognized Expert Contributor
                • Dec 2007
                • 750

                #8
                Originally posted by asmasm1
                thanx dirtbag

                I am developing application for loan purposes and i have to calculate irr
                textbox2.text specify the no installments
                those no equal installments are added to arraylist
                <code>
                //For i = 0 To TextBox2.Text??
                // Add elements of array list
                //for(int 0;i<Convert.ToI nt32(TextBox.Te xt);i++)//

                ir = //YOURFUNCTION(pa y[index],0.1,2);
                //(pay (TextBox2.Text + 1), 0.1), 2)
                // what exactly are you passing in the function?
                </code>

                passing arraylist (pay(x) as ist parameter and guess (0.1)
                as i have also mentioned whole problem in my posts
                thanks again for response
                where exactly have you got d prob? post some code n error message...

                Comment

                • asmasm1
                  New Member
                  • Aug 2008
                  • 7

                  #9
                  hi dirtbag
                  'code Starts
                  Dim i As Int16
                  Dim pay As New ArrayList()
                  For i = 0 To TextBox2.Text
                  pay.Add(TextBox 5.Text)
                  Next
                  pay.Add(-TextBox1.Text)
                  Dim ir As Double
                  ir = Math.Round(Micr osoft.VisualBas ic.Financial.IR R(pay (TextBox2.Text + 1), 0.1), 2)
                  TextBox7.Text = ir
                  'code Ends

                  GETTTING THIS ERROR MESSAGE
                  Unable to cast object of type 'System.Double' to type 'System.Double[]'.

                  Comment

                  • PRR
                    Recognized Expert Contributor
                    • Dec 2007
                    • 750

                    #10
                    Originally posted by asmasm1
                    hi dirtbag
                    'code Starts
                    Dim i As Int16
                    Dim pay As New ArrayList()
                    For i = 0 To TextBox2.Text
                    pay.Add(TextBox 5.Text)
                    Next
                    pay.Add(-TextBox1.Text)
                    Dim ir As Double
                    ir = Math.Round(Microsoft.Visu alBasic.Financi al.IRR(pay (TextBox2.Text + 1), 0.1), 2)
                    TextBox7.Text = ir
                    'code Ends

                    GETTTING THIS ERROR MESSAGE
                    Unable to cast object of type 'System.Double' to type 'System.Double[]'.
                    As far as i can see your function returns Double[] ; so declare double array ..
                    Dim ir as Double[]; or in C#
                    double[] ir;

                    Comment

                    • asmasm1
                      New Member
                      • Aug 2008
                      • 7

                      #11
                      could any body has solved my problem as i am not getting the solution yet

                      Comment

                      Working...