首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用financial.ppmt方法的贷款计算器

使用financial.ppmt方法的贷款计算器
EN

Stack Overflow用户
提问于 2016-05-03 00:11:07
回答 1查看 746关注 0票数 0

任务是让用户输入本金金额,并从组合框中选择利率以及条款。UI应该在标签中显示每月付款,以及在多行文本框中支付给本金和利息的金额。我在完成代码时遇到了麻烦。我不太确定我是否没有完全得到financial.ppmt方法,或者不仅仅是我的月付款显示不准确,但我无法正确地显示多行文本框信息(本金和利息金额)。如果有人能帮我,或者至少指点我一个类似的项目,我会非常感谢的!

代码语言:javascript
复制
Option Explicit On
Option Strict On
Option Infer Off


Public Class MainForm
Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click
    Me.Close()

End Sub

Private Sub CalcButton_Click(sender As Object, e As EventArgs) Handles CalcButton.Click
    'Calculates the monthly payments on a loan using 
    'annual interest rates from 2%-10% and terms from 1-30 years

    Dim Principal As Double
    Dim term As Integer
    Dim rate As Double
    Dim monthlyPayment As Double
    Dim interest As Double

    'assign input to variables
    Double.TryParse(PrincipalTextBox.Text, Principal)
    term = Convert.ToInt32(TermComboBox.SelectedItem)

    'clear text boxes
    PaymentValue.Text = String.Empty
    PrincipleAndInterestBox.Text = String.Empty

    'calculate and display monthly payments
    monthlyPayment = -Financial.Pmt(rate / 12, 12, term * 12, Principal)
    MonthlyPaymentLabel.Text = monthlyPayment.ToString("C2")

    'Calculate the amount applied to principal and interest
    For per As Integer = 12 To 1 Step -1
        Principal = -Financial.PPmt(rate / 12, per, 12, Principal)
        interest = monthlyPayment - Principal
        PrincipleAndInterestBox.Text = Principal.ToString("C2") & "         " & interest.ToString("C2") & ControlChars.NewLine

    Next per
    PrincipleAndInterestBox.Focus()
End Sub

Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles Me.Load
    'fill termComboBox
    For term As Integer = 1 To 30
        TermComboBox.Items.Add(term.ToString)
    Next term
    TermComboBox.SelectedItem = "10"

    'fill interestRateComboBox
    For rate As Integer = 2 To 10
        InterestRateComboBox.Items.Add(rate.ToString)
    Next rate
    InterestRateComboBox.SelectedItem = "4"
End Sub

端级

EN

回答 1

Stack Overflow用户

发布于 2016-05-03 06:54:24

转到textbox属性并选择multiline = true

在循环中,您正在为textbox分配新值,而忽略了现有值。

代码语言:javascript
复制
PrincipleAndInterestBox.Text = PrincipleAndInterestBox.Text & Principal.ToString("C2") & "         " & interest.ToString("C2") & ControlChars.NewLine

代码语言:javascript
复制
textBox1.Multiline = True
textBox1.ScrollBars = ScrollBars.Vertical
textBox1.WordWrap = True
textBox1.Text = "Welcome!" & Environment.NewLine & "Second Line"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36993567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档