4 Replies - 3246 Views - Last Post: 06 May 2012 - 09:08 PM Rate Topic: -----

#1 SplinteredChaos  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 112
  • Joined: 15-September 11

value of type -1 dimensional array of double cannot be converted

Posted 06 May 2012 - 03:47 PM

I think I am missing something really simple. I want the user to be able to select a particular interest rate and term from radio buttons (in separate groups), the values for the buttons are to be stored in an array. Then they click the calculate button and it does it's magic and pops the result in to another field. I think I have things set up roughly the way it needs to. What I'm running in to right now is the term variable in the calculation formula is coming up with a blue underline stating that "value of type -1 dimensional array of double cannot be converted to a double". So as a result nothing is working right. I don't know where exactly I've gone wrong. If I change the data types nothing seems to change.

Help?

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim loanAmount As Integer = AmountBorrowedBox1.Text


        'create arrays to hold interest rate and length of loan
        Dim Interest() As Decimal = {5.35, 5.5, 5.75}
        Dim term() As Integer = {7, 15, 30}

        'establish value of radio buttons
        If InterestRate1.Checked = True Then
            apr = Interest(0)
        End If
        If InterestRate2.Checked = True Then
            apr = Interest(1)
        End If
        If InterestRate3.Checked = True Then
            apr = Interest(2)
        End If

        If Term1.Checked = True Then
            length = term(0)
        End If
        If Term2.Checked = True Then
            length = term(1)
        End If
        If Term3.Checked = True Then
            length = term(2)
        End If

        payment = (loanAmount * Math.Pow((apr / 12) + 1, (term)) * apr / 12) / (Math.Pow(apr / 12 + 1, (term)) - 1)
        'apply payment to textbox
        TextBox2.Text = "$" + payment.ToString

        'validate input
        If IsNumeric(AmountBorrowedBox1.Text) = False Then

            MsgBox("Loan amount must be numeric. Please enter a valid loan amount.", MsgBoxStyle.Exclamation)
            AmountBorrowedBox1.Clear()
            AmountBorrowedBox1.Focus()
        End If



    End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: value of type -1 dimensional array of double cannot be converted

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: value of type -1 dimensional array of double cannot be converted

Posted 06 May 2012 - 03:50 PM

Which line is the error in?
Was This Post Helpful? 0
  • +
  • -

#3 SplinteredChaos  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 112
  • Joined: 15-September 11

Re: value of type -1 dimensional array of double cannot be converted

Posted 06 May 2012 - 03:52 PM

Line 30 in the posted code. It is the payment calculation formula that has the error.
Was This Post Helpful? 0
  • +
  • -

#4 Nerfpl  Icon User is offline

  • D.I.C Head

Reputation: 43
  • View blog
  • Posts: 165
  • Joined: 15-January 12

Re: value of type -1 dimensional array of double cannot be converted

Posted 06 May 2012 - 04:11 PM

didn't you meant to use 'length' instead of (term) in your formula?

You use
Math.Pow(double,double)
as 
Math.Pow(double,array) //incorrect


This post has been edited by Nerfpl: 06 May 2012 - 04:12 PM

Was This Post Helpful? 0
  • +
  • -

#5 SplinteredChaos  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 112
  • Joined: 15-September 11

Re: value of type -1 dimensional array of double cannot be converted

Posted 06 May 2012 - 09:08 PM

Wow, thank you Nerf. I can't believe I missed that. I really appreciate the swift feedback. Now I just need to get the calculation to come out right. Using a test value of 200,000$ at 5.75% over 30 years I should have a return of $1167.15. My test returned a value of more like 9800. I've had this problem before in other programs. I think it might be something with the definition of the term of the loan.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1