Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Aug 2008
Posts: 7
#1: Sep 10 '08
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(TextBox5.Text)
Next
pay.Add(-TextBox1.Text)
Dim ir As Double
ir = Math.Round(Microsoft.VisualBasic.Financial.IRR(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's Avatar
Expert
 
Join Date: Nov 2006
Location: India,Pune
Posts: 686
#2: Sep 10 '08

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


Hi,

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

ir = Math.Round(Microsoft.VisualBasic.Financial.IRR(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.
Newbie
 
Join Date: Aug 2008
Posts: 7
#3: Sep 12 '08

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


thanks shweta123

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

ir = Math.Round(Microsoft.VisualBasic.Financial.IRR(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
shweta123's Avatar
Expert
 
Join Date: Nov 2006
Location: India,Pune
Posts: 686
#4: Sep 13 '08

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


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.

Quote:

Originally Posted by asmasm1

thanks shweta123

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

ir = Math.Round(Microsoft.VisualBasic.Financial.IRR(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

Newbie
 
Join Date: Aug 2008
Posts: 7
#5: Sep 15 '08

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


Quote:

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
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 701
#6: Sep 15 '08

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


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

Expand|Select|Wrap|Line Numbers
  1.  
  2. int i;
  3.             ArrayList pay =new ArrayList();
  4.             // Better Option is 
  5.             List<int> pay1=new List<int>();
  6.  
  7. //For i = 0 To TextBox2.Text?? 
  8.             // What exactly are you doin here?
  9.             //for(int 0;i<Convert.ToInt32(TextBox.Text);i++)//
  10.  
  11. ir = //YOURFUNCTION(pay[index],0.1,2);
  12. //(pay (TextBox2.Text + 1), 0.1), 2)
  13. // what exactly are you passing in the function?
  14.  
  15.  
Newbie
 
Join Date: Aug 2008
Posts: 7
#7: Sep 17 '08

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


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
Expand|Select|Wrap|Line Numbers
  1. //For i = 0 To TextBox2.Text?? 
  2.             // Add elements of array list
  3.             //for(int 0;i<Convert.ToInt32(TextBox.Text);i++)//
  4.  
  5. ir = //YOURFUNCTION(pay[index],0.1,2);
  6. //(pay (TextBox2.Text + 1), 0.1), 2)
  7. // what exactly are you passing in the function?
  8.  
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
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 701
#8: Sep 17 '08

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


Quote:

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.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?
</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...
Newbie
 
Join Date: Aug 2008
Posts: 7
#9: Sep 18 '08

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


hi dirtbag
'code Starts
Dim i As Int16
Dim pay As New ArrayList()
For i = 0 To TextBox2.Text
pay.Add(TextBox5.Text)
Next
pay.Add(-TextBox1.Text)
Dim ir As Double
ir = Math.Round(Microsoft.VisualBasic.Financial.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[]'.
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 701
#10: Sep 18 '08

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


Quote:

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(TextBox5.Text)
Next
pay.Add(-TextBox1.Text)
Dim ir As Double
ir = Math.Round(Microsoft.VisualBasic.Financial.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;
Newbie
 
Join Date: Aug 2008
Posts: 7
#11: Sep 22 '08

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


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