2016-05-03 10 views
0

Die Aufgabe ist es, einen Benutzer geben Sie den Kapitalbetrag sowie den Zinssatz aus einer Combo-Box sowie die Bedingungen auswählen. Auf der Benutzeroberfläche sollte die monatliche Zahlung in einem Label angezeigt werden. Außerdem sollte angegeben werden, wie viel von dieser Zahlung an den Auftraggeber geht und wie viel in eine mehrzeilige Textbox investiert wird. Ich habe Probleme, meinen Code zu vervollständigen. Ich bin nicht ganz sicher, ob ich nicht ganz die finanzielle.ppmt-Methode bekomme oder was, aber nicht nur, dass meine monatliche Zahlung nicht genau angezeigt wird, aber ich kann die mehrzeiligen Textbox-Informationen (Hauptbetrag und Zinsbetrag) nicht anzeigen richtig. Wenn jemand mir helfen kann oder zumindest auf ein ähnliches Programm hinweist, würde ich mich sehr bedanken!Darlehen Rechner mit financial.ppmt Methode

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 

End Class

Antwort

0

zu Textbox Eigenschaften gehen und mehrzeilige wählen = true

in Schleife Sie neuen Wert zuweisen den vorhandenen Wert in Textbox und fehlt.

PrincipleAndInterestBox.Text = PrincipleAndInterestBox.Text & Principal.ToString("C2") & "   " & interest.ToString("C2") & ControlChars.NewLine 

Oder

textBox1.Multiline = True 
textBox1.ScrollBars = ScrollBars.Vertical 
textBox1.WordWrap = True 
textBox1.Text = "Welcome!" & Environment.NewLine & "Second Line"