Throwing Exception Error

Throwing Missing Member Exception.

Page 1 of 1

10 Replies - 1302 Views - Last Post: 24 May 2010 - 04:27 AM Rate Topic: -----

#1 ImAGoin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 23-May 10

Throwing Exception Error

Posted 23 May 2010 - 08:12 AM

Attached File  HarlessSmithIA3.zip (125.77K)
Number of downloads: 90This program is supposed to calculate the ever popular mortgage payment and amortize the loan in a list box. I keep throwing this error "Missing Member Exception" and can not find out how to fix it anywhere. Because of the error I can't even see if I can even get a calculation in the text box, let alone if the amortization will run. The purple text is where the exception is. Any help would be appreciated.

Public Class HarlessSmithIA3

    Dim LoanAmt, Int, Result, Term As Double
    Dim txtIntRate As New Object
    Dim txtLoanAmount As New Object
    Dim txtLoanTerm As New Object
    Dim txtMonthlyPayment As New Object

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click

        'Exit Program

        Me.Close()

    End Sub

    Private Sub Calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        'Calculate the Monthly Payment

        Dim LoanAmount As Double 'loan amount 
        Dim IntRate As Integer 'interest rate  
        Dim LoanTerm As Integer 'number of years 
        Dim MonthlyPayment As Double 'payment amount 

        txtLoanAmount.Text = FormatCurrency(LoanAmount)
        txtIntRate.Text = FormatPercent(IntRate)
        txtLoanTerm.Text = FormatNumber(LoanTerm)


        [color="#800080"]LoanAmount = CDbl(txtLoanAmount.Text)
        IntRate = CDbl(txtIntRate.Text) / 100
        LoanTerm = CDbl(txtLoanTerm.Text) * 12
        MonthlyPayment = (txtMonthlyPayment.ToString)[/color]
        

        MonthlyPayment = Pmt(txtIntRate / 12, txtLoanTerm * 12, txtLoanAmount * -1)


    End Sub

    Private Sub Amort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Amort.SelectedIndexChanged

        Dim LoanAmount, IntRate, MonthlyPayment, LoanTerm As Double

        Dim PVal, FVal, mPayments As Integer
        Dim APR, iPayment, TotInt As Double
        Dim pPayment, TotPrincipal, Balance As Double
        PVal = LoanAmount
        FVal = 0
        APR = IntRate / 12
        mPayments = LoanTerm * 12
        Balance = LoanAmount
        For period As Integer = 1 To mPayments
            iPayment = IPmt(APR, period, mPayments, -PVal, FVal, 1)
            pPayment = PPmt(APR, period, mPayments, -PVal, FVal, 1)
            Amort.Items.Add(FormatCurrency(TotPrincipal).PadRight(25) & FormatCurrency(iPayment).PadRight(25) & FormatCurrency(Balance).PadLeft(25))
            Debug.WriteLine(" Pmnt #" & period & " -> Principle =" & FormatCurrency(TotPrincipal).PadRight(14) & " Int Paid for Payment #" & period & "  is " & FormatCurrency(iPayment) & "  Bal. =" & FormatCurrency(Balance))
            TotInt = TotInt + iPayment
            TotPrincipal = TotPrincipal + pPayment
            MonthlyPayment = CDbl(iPayment + pPayment)
            Balance = Balance - (MonthlyPayment - iPayment)
        Next

        Amort.Items.Add(" _______________________________")
        Amort.Items.Add(" Total interest paid: " & FormatCurrency(TotInt))
        Amort.Items.Add(" _______________________________")
        Amort.Items.Add(" Total Paid after: " & mPayments & "  Payments = " & FormatCurrency(TotInt + TotPrincipal))
        Amort.Items.Add(" _______________________________")
        Amort.Items.Add(" Last Payment is " & FormatCurrency(iPayment))
        'Format answer'        
        MonthlyPayment = CDbl(iPayment + pPayment)

        txtMonthlyPayment.Text = FormatCurrency(MonthlyPayment)

    End Sub

    
    
    Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll

    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Throwing Exception Error

#2 Aj14  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 60
  • Joined: 17-April 10

Re: Throwing Exception Error

Posted 23 May 2010 - 09:00 AM

which bit?
Was This Post Helpful? 0
  • +
  • -

#3 ImAGoin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 23-May 10

Re: Throwing Exception Error

Posted 23 May 2010 - 09:02 AM

View PostAj14, on 23 May 2010 - 08:00 AM, said:

which bit?


This part is where it starts. It shows no errors but throws this when I debug it.

 LoanAmount = CDbl(txtLoanAmount.Text) 
        IntRate = CDbl(txtIntRate.Text) / 100 
        LoanTerm = CDbl(txtLoanTerm.Text) * 12 
        MonthlyPayment = (txtMonthlyPayment.ToString)[/color] 
         
 
        MonthlyPayment = Pmt(txtIntRate / 12, txtLoanTerm * 12, txtLoanAmount * -1) 



Thanks
Was This Post Helpful? 0
  • +
  • -

#4 Charles:)  Icon User is online

  • D.I.C Head

Reputation: 52
  • View blog
  • Posts: 148
  • Joined: 26-November 09

Re: Throwing Exception Error

Posted 23 May 2010 - 01:18 PM

 LoanAmount = CDbl(txtLoanAmount.Text) 
        IntRate = CDbl(txtIntRate.Text) / 100 
        LoanTerm = CDbl(txtLoanTerm.Text) * 12 
        MonthlyPayment = (txtMonthlyPayment.ToString)
         
 
        MonthlyPayment = Pmt(txtIntRate / 12, txtLoanTerm * 12, txtLoanAmount * -1) 



It looks like txtLoanAmount, txtIntRate and txtLoanTerm are supposed to be text box controls? If so then why have you declared them as objects? That could well be the cause of your "missing member exception".

Also IntRate and LoanTerm are integers but you're trying to assign doubles to them. I suggest turning on 'option strict' to avoid that sort of thing.

This post has been edited by Charles:): 23 May 2010 - 01:19 PM

Was This Post Helpful? 0
  • +
  • -

#5 ImAGoin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 23-May 10

Re: Throwing Exception Error

Posted 23 May 2010 - 04:41 PM

View PostCharles:), on 23 May 2010 - 12:18 PM, said:

 LoanAmount = CDbl(txtLoanAmount.Text) 
        IntRate = CDbl(txtIntRate.Text) / 100 
        LoanTerm = CDbl(txtLoanTerm.Text) * 12 
        MonthlyPayment = (txtMonthlyPayment.ToString)
         
 
        MonthlyPayment = Pmt(txtIntRate / 12, txtLoanTerm * 12, txtLoanAmount * -1) 



It looks like txtLoanAmount, txtIntRate and txtLoanTerm are supposed to be text box controls? If so then why have you declared them as objects? That could well be the cause of your "missing member exception".

Also IntRate and LoanTerm are integers but you're trying to assign doubles to them. I suggest turning on 'option strict' to avoid that sort of thing.


Thank you, but I am not sure how that should be expressed. I can't do Dim ..... as Text. I have been working on this for so long I can't see the forest through the trees if you know what I mean.
Was This Post Helpful? 0
  • +
  • -

#6 Aj14  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 60
  • Joined: 17-April 10

Re: Throwing Exception Error

Posted 23 May 2010 - 04:56 PM

without downloading the project, and going on what was said above...if txtLoanAmount etc are textbox controls then you dont need to declare them if you use the corresponding textboxes on your form...?
Was This Post Helpful? 0
  • +
  • -

#7 ImAGoin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 23-May 10

Re: Throwing Exception Error

Posted 23 May 2010 - 05:02 PM

View PostAj14, on 23 May 2010 - 03:56 PM, said:

without downloading the project, and going on what was said above...if txtLoanAmount etc are textbox controls then you dont need to declare them if you use the corresponding textboxes on your form...?


There are text boxes and they are set to[]String but for whatever reason I keep getting the squiggly underline under the elements if they aren't declared. I am just about ready to pack it in and major in basket weaving.
Was This Post Helpful? 0
  • +
  • -

#8 Aj14  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 60
  • Joined: 17-April 10

Re: Throwing Exception Error

Posted 23 May 2010 - 05:40 PM

now i havent checked the calculations are correct as im not 100% sure how your prog. is supposed to work..paste it all in over your current code..you may also want to check out coding standards (ie. camal case, pascal etc) i changed a few of them but by no means enough..hope this helps


Public Class HarlessSmithIA3

    Dim dbl_LoanAmt, Int, Result, Term As Double
    Dim dbl_IntRate As Double
    Dim dbl_LoanAmount As Double
    Dim dbl_LoanTerm As Double
    Dim dbl_MonthlyPayment As Double

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click

        'Exit Program

        Me.Close()

    End Sub

    Private Sub Calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        'Calculate the Monthly Payment

        
        dbl_LoanAmount = FormatCurrency(LoanAmount.Text)
        dbl_IntRate = IntRate.Text
        dbl_LoanTerm = FormatNumber(LoanTerm.Text)


        'LoanAmount = CDbl(txtLoanAmount)
        dbl_IntRate = dbl_IntRate / 100
        dbl_LoanTerm = dbl_LoanTerm * 12
        dbl_MonthlyPayment = Me.MonthlyPayment.Text


        

        dbl_MonthlyPayment = Pmt(dbl_IntRate / 12, dbl_LoanTerm * 12, dbl_LoanAmount * -1)

        MonthlyPayment.Text = dbl_MonthlyPayment


    End Sub

    Private Sub Amort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Amort.SelectedIndexChanged

        Dim LoanAmount, IntRate, MonthlyPayment, LoanTerm As Double

        Dim PVal, FVal, mPayments As Integer
        Dim APR, iPayment, TotInt As Double
        Dim pPayment, TotPrincipal, Balance As Double
        PVal = LoanAmount
        FVal = 0
        APR = IntRate / 12
        mPayments = LoanTerm * 12
        Balance = LoanAmount
        For period As Integer = 1 To mPayments
            iPayment = IPmt(APR, period, mPayments, -PVal, FVal, 1)
            pPayment = PPmt(APR, period, mPayments, -PVal, FVal, 1)
            Amort.Items.Add(FormatCurrency(TotPrincipal).PadRight(25) & FormatCurrency(iPayment).PadRight(25) & FormatCurrency(Balance).PadLeft(25))
            Debug.WriteLine(" Pmnt #" & period & " -> Principle =" & FormatCurrency(TotPrincipal).PadRight(14) & " Int Paid for Payment #" & period & "  is " & FormatCurrency(iPayment) & "  Bal. =" & FormatCurrency(Balance))
            TotInt = TotInt + iPayment
            TotPrincipal = TotPrincipal + pPayment
            MonthlyPayment = CDbl(iPayment + pPayment)
            Balance = Balance - (MonthlyPayment - iPayment)
        Next

        Amort.Items.Add(" _______________________________")
        Amort.Items.Add(" Total interest paid: " & FormatCurrency(TotInt))
        Amort.Items.Add(" _______________________________")
        Amort.Items.Add(" Total Paid after: " & mPayments & "  Payments = " & FormatCurrency(TotInt + TotPrincipal))
        Amort.Items.Add(" _______________________________")
        Amort.Items.Add(" Last Payment is " & FormatCurrency(iPayment))
        'Format answer'        
        MonthlyPayment = CDbl(iPayment + pPayment)

        MonthlyPayment = FormatCurrency(MonthlyPayment)

    End Sub

    
    
    Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll

    End Sub
End Class





Was This Post Helpful? 1
  • +
  • -

#9 ImAGoin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 23-May 10

Re: Throwing Exception Error

Posted 23 May 2010 - 06:04 PM

View PostAj14, on 23 May 2010 - 04:40 PM, said:

now i havent checked the calculations are correct as im not 100% sure how your prog. is supposed to work..paste it all in over your current code..you may also want to check out coding standards (ie. camal case, pascal etc) i changed a few of them but by no means enough..hope this helps


Public Class HarlessSmithIA3

    Dim dbl_LoanAmt, Int, Result, Term As Double
    Dim dbl_IntRate As Double
    Dim dbl_LoanAmount As Double
    Dim dbl_LoanTerm As Double
    Dim dbl_MonthlyPayment As Double

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click

        'Exit Program

        Me.Close()

    End Sub

    Private Sub Calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        'Calculate the Monthly Payment

        
        dbl_LoanAmount = FormatCurrency(LoanAmount.Text)
        dbl_IntRate = IntRate.Text
        dbl_LoanTerm = FormatNumber(LoanTerm.Text)


        'LoanAmount = CDbl(txtLoanAmount)
        dbl_IntRate = dbl_IntRate / 100
        dbl_LoanTerm = dbl_LoanTerm * 12
        ************dbl_MonthlyPayment = Me.MonthlyPayment.Text**************


        

        dbl_MonthlyPayment = Pmt(dbl_IntRate / 12, dbl_LoanTerm * 12, dbl_LoanAmount * -1)

        MonthlyPayment.Text = dbl_MonthlyPayment


    End Sub

    Private Sub Amort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Amort.SelectedIndexChanged

        Dim LoanAmount, IntRate, MonthlyPayment, LoanTerm As Double

        Dim PVal, FVal, mPayments As Integer
        Dim APR, iPayment, TotInt As Double
        Dim pPayment, TotPrincipal, Balance As Double
        PVal = LoanAmount
        FVal = 0
        APR = IntRate / 12
        mPayments = LoanTerm * 12
        Balance = LoanAmount
        For period As Integer = 1 To mPayments
            iPayment = IPmt(APR, period, mPayments, -PVal, FVal, 1)
            pPayment = PPmt(APR, period, mPayments, -PVal, FVal, 1)
            Amort.Items.Add(FormatCurrency(TotPrincipal).PadRight(25) & FormatCurrency(iPayment).PadRight(25) & FormatCurrency(Balance).PadLeft(25))
            Debug.WriteLine(" Pmnt #" & period & " -> Principle =" & FormatCurrency(TotPrincipal).PadRight(14) & " Int Paid for Payment #" & period & "  is " & FormatCurrency(iPayment) & "  Bal. =" & FormatCurrency(Balance))
            TotInt = TotInt + iPayment
            TotPrincipal = TotPrincipal + pPayment
            MonthlyPayment = CDbl(iPayment + pPayment)
            Balance = Balance - (MonthlyPayment - iPayment)
        Next

        Amort.Items.Add(" _______________________________")
        Amort.Items.Add(" Total interest paid: " & FormatCurrency(TotInt))
        Amort.Items.Add(" _______________________________")
        Amort.Items.Add(" Total Paid after: " & mPayments & "  Payments = " & FormatCurrency(TotInt + TotPrincipal))
        Amort.Items.Add(" _______________________________")
        Amort.Items.Add(" Last Payment is " & FormatCurrency(iPayment))
        'Format answer'        
        MonthlyPayment = CDbl(iPayment + pPayment)

        MonthlyPayment = FormatCurrency(MonthlyPayment)

    End Sub

    
    
    Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll

    End Sub
End Class






Thanks, that did get rid of that particular problem but now I am throwing another exception "Invalid Cast Exception" Thanks for your help....;-)
Was This Post Helpful? 0
  • +
  • -

#10 Aj14  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 60
  • Joined: 17-April 10

Re: Throwing Exception Error

Posted 23 May 2010 - 06:14 PM

i wasnt getting any errors..where is it throwing the exception?
Was This Post Helpful? 1
  • +
  • -

#11 Charles:)  Icon User is online

  • D.I.C Head

Reputation: 52
  • View blog
  • Posts: 148
  • Joined: 26-November 09

Re: Throwing Exception Error

Posted 24 May 2010 - 04:27 AM

dbl_IntRate = IntRate.Text

This looks like a potentially invalid cast to me. If you have option strict on then this won't compile.

Try changing it to:

dbl_IntRate = CDbl(IntRate.Text)

This post has been edited by Charles:): 24 May 2010 - 04:28 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1