'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
Page 1 of 1
2 Replies - 1696 Views - Last Post: 16 December 2011 - 09:12 PM
vbNewline doesn't work
Posted 16 December 2011 - 08:04 PM
Peace be upon you and good morning. I was trying to make a PTPTN loan calculator that calculate the required monthly payment accordingly. But when I tried to print into the text box, it only exist for a line. The vbNewLine or vbcrlf didn't seems to work. The following is my code. Is there any limitation in using vbNewline that I need to know? I also accept any other suggestion or advice regarding my code as I am still learning.
Replies To: vbNewline doesn't work
Re: vbNewline doesn't work
Posted 16 December 2011 - 08:08 PM
Edit Controls (Text Boxes) are single line by default. You have to change it to multiline for carriage returns to show multiple lines. Click on your text box, and somewhere in the properties list change multi line to true.
Page 1 of 1