this for loop runs a set number of times. it is used to execute a group of lines repeatedly. computing the monthly loan payment is a good demonstration for a loop. the monthly loan payment is a fixed sum that is composed of both interest and principle repayment.
Please help me!
Please help me!
Code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim loan As Single = Val(TextBox1.Text)
Dim interest As Single = 9%
Dim numberofyears As Single = Val(TextBox2.Text)
Dim monthlypayment, monthlyrate, numberofpayments, count As Single
monthlyrate = 1 + (interest / (12 * 100))
numberofpayments = numberofyears * 12
monthlypayment = (loan * interest * monthlyrate ^ numberofpayments) / (1200 * ((monthlyrate ^ numberofpayments) - 1))
Dim interestpart, loanpart, Balance As Single
For count = 1 To numberofpayments
interestpart = loan * (interest * 9) / 12
loanpart = monthlypayment - interestpart
Balance = loan - loanpart
Next
Dim paymentoutput As Single
Label1.Text = paymentoutput & "Payment #" & count & vbTab & _
Format(loan, "C") & " " & vbTab & FormatCurrency(interestpart) & vbTab & _
FormatCurrency(loanpart) & vbTab & FormatCurrency(Balance) & vbCrLf
End Sub
End Class
Comment