'PTPTN
'Calculate the amount that a student must pay every month to pay for their PTPTN study loan.
' Look for:
' 1. PTPTN interest rate = 1% per annum
' 2. Principle = RM 12,500
' 3. Years to pay < 10 years
'E.g.:
'Year | Monthly Payment(RM) | Balance Payment(RM)
' 1 | | 12625
' 2
' Expected to have looping to display part.
'Formula :
'interest = principle * interestRate/100
'yearlyPayment = principle / yearsToPay
'monthlyPayment = (yearlyPayment + interest)/12
'totalPayment = totalPayment yearlyPayment
Option Explicit
Dim interest, interestRate, totalPayment, principle, yearlyPayment, monthlyPayment As Double
Dim yearsToPay, yearCounter As Integer
Dim stringCounter As String
Const monthPerYear As Integer = 12
Private Sub cmdCalculate_Click()
interestRate = txtInterestRate.Text
principle = txtTotalLoan.Text
yearsToPay = txtYears2Pay.Text
On Error GoTo errorLabel1 'errorchecking
totalPayment = principle
yearlyPayment = principle / yearsToPay
interest = interestRate / 100 * principle
stringCounter = "Year" & vbTab & "Monthly Payment(RM)" & vbTab & "Balance Payment(RM)"
stringCounter = stringCounter & vbNewLine
For yearCounter = 1 To 10
monthlyPayment = (yearlyPayment + interest) / monthPerYear
totalPayment = totalPayment - yearlyPayment
stringCounter = stringCounter & yearCounter & vbTab & monthlyPayment & vbTab & totalPayment & vbNewLine
Next
txtDisplay.Text = stringCounter
txtTotalLoan.Enabled = False
txtYears2Pay.Enabled = False
cmdCalculate.Enabled = False
txtDisplay.Enabled = True
Exit Sub
errorLabel1: 'end when have error
MsgBox "Error! Please try again."
End Sub
Private Sub cmdClear_Click()
interest = interestRate = totalPayment = principle = yearlyPayment = monthlyPayment = yearsToPay = 0
txtYears2Pay.Text = "0"
txtTotalLoan.Text = "0"
txtDisplay.Text = ""
txtTotalLoan.Enabled = True
txtYears2Pay.Enabled = True
cmdCalculate.Enabled = True
txtDisplay.Enabled = False
MsgBox "Cleared!"
End Sub
Private Sub cmdExit_Click()
MsgBox "Have a great day! ^_^/>"
End
End Sub
Private Sub Form_Load()
MsgBox "Hello! :)/>"
End Sub

New Topic/Question
Reply




MultiQuote






|