使用的贷款计算器,当圈时

时间:2016-11-10 02:59:44

标签: vb.net

我正在创建一个贷款计算器,我的循环一直在破碎。我的统计数据是正确的,但我现在需要移动到具有更多统计数据的ListBox。

我无法在循环工作时获得此功能我尝试过不同的方法但无济于事。这让我头疼,我不知道自己做错了什么。

Public Class Form1
    Dim principleamount As Decimal
    Dim numberofyears As Decimal
    Dim interestrate As Decimal
    Dim total As Decimal
    Dim paymentnumber As Decimal
    Dim currentbalance As Decimal
    Dim interestfortheperiod As Decimal
    Dim paymentamouhnt As Decimal
    Dim newbalance As Decimal
    Dim numberofpayments As Decimal
    Dim payment As Decimal
    Dim interestamount As Decimal
    Dim numberofperiods As Integer

    Private Sub btncalc_Click(sender As Object, e As EventArgs) Handles btncalc.Click

        principleamount = txtprinciple.Text
        numberofyears = txtyears.Text

        'interest rate 
        If rba.Checked Then
            interestrate = 1.035
        End If
        If rbb.Checked Then
            interestrate = 1.04
        End If
        If rbc.Checked Then
            interestrate = 1.65
        End If
        If rbc.Checked Then
            interestrate = 1.08
        End If
        If rbd.Checked Then
            interestrate = 1.08
        End If
        If rbe.Checked Then
            interestrate = 0.1
        End If

        'monthly,weekly paymentplan
        If rbmonthly.Checked Then
            numberofpayments = numberofyears * 12
            interestfortheperiod = interestrate / 12
        End If
        If rbweekly.Checked Then
            numberofpayments = numberofyears * 26
            interestfortheperiod = interestrate / 26
        End If

        payment = (principleamount * interestfortheperiod) / (1 - (1 + interestfortheperiod) ^ -numberofpayments)

        txtpayment.Text = Format(payment, "#.00")

        While principleamount >= 0
            paymentnumber += 1
            lbpaydetails.Items.Add("Payment Number: " & paymentnumber & " Current Balance: " &  & "Interest for the Period: " &  & "Payment Amount:" &  & "new Balance:" & )
        End While
    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

while循环是永远的,所以你需要找到一种方法来减少' princlipleamount' 循环中。我不完全确定代码的作用以及它与表单的行为方式,所以我实际上无法解决它。

P.S。 如果您想要获得支付数量'要消极,不要像这样在它前面划一条:

payment = (principleamount * interestfortheperiod) / (1 - (1 + interestfortheperiod) ^ -numberofpayments))

但是把它放在Math.Abs​​()中就像这样:

payment = (principleamount * interestfortheperiod) / (1 - (1 + interestfortheperiod) ^ Math.Abs(numberofpayments))

另外,你最后有一个支架缺失,我为你填写了。

祝你好运! ;)