任务是让用户输入本金金额,并从组合框中选择利率以及条款。UI应该在标签中显示每月付款,以及在多行文本框中支付给本金和利息的金额。我在完成代码时遇到了麻烦。我不太确定我是否没有完全得到financial.ppmt方法,或者不仅仅是我的月付款显示不准确,但我无法正确地显示多行文本框信息(本金和利息金额)。如果有人能帮我,或者至少指点我一个类似的项目,我会非常感谢的!
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端级
发布于 2016-05-03 06:54:24
转到textbox属性并选择multiline = true
在循环中,您正在为textbox分配新值,而忽略了现有值。
PrincipleAndInterestBox.Text = PrincipleAndInterestBox.Text & Principal.ToString("C2") & " " & interest.ToString("C2") & ControlChars.NewLine或
textBox1.Multiline = True
textBox1.ScrollBars = ScrollBars.Vertical
textBox1.WordWrap = True
textBox1.Text = "Welcome!" & Environment.NewLine & "Second Line"https://stackoverflow.com/questions/36993567
复制相似问题