INSTRUCTIONS FOR CREATING THE CALCULATE A MONTHLY PAYMENT FORM

We are now ready to construct FRMPAY.FRM FRMPAY.FRM form has 14 objects OBJECT PROPERTY VALUE 1. Form Caption Payment Name FrmPay WindowState Maximized 2. Label Caption Monthly Car Payment Autosize True Fontsize 18 3. Label Caption Principal: Autosize True Fontsize 12 4. Label Caption Interest: Autosize True Fontsize 12 5. Label Caption Term: Autosize True Fontsize 12 6. Label Caption Monthly Payment Autosize True Fontsize 12 7. Label Caption blank (We’ll put a payment here after we calculate it) Name Lblpay Autosize False Border Fixed Single 8. Textbox Name TxtPrin FontSize 12 9.ComboBox Name CboInterest FontSize 12 10. ListBox Name LstTerm FontSize 12 11.Horizontal Scroll Bar Name HsbPrin Max 30000 Min 5000 SmallChange 250 12. Command Button Name CmdCompute Caption Compute 13. Command Button Name CmdExit Caption Exit 14. Line Name Line1 Now we must program this form. What do we want to happen when the user hits the COMPUTE button? We want to calculate a monthly payment based on the principal, interest rate, and term of loan and present it to the user in the LBLPAY.CAPTION variable. We will use a built-in function (like a built-in LOTUS functions) called PMT: PMT Description: Returns the payment for an annuity based on periodic, constant payments and a constant interest rate. An annuity is a series of constant cash payments made over a period of time. An annuity can be a loan (such as a home mortgage) or an investment (such as a monthly savings plan). The Pmt function uses the following numeric arguments: Syntax: Pmt(irate, numper, pval, fval, duepay) irate: Interest rate per period. For example, if you get a car loan at an annual percentage rate (APR) of 10 percent and make monthly payments, the rate per period is 0.1/12, or 0.0083. numper:Total number of payment periods in the annuity. For example, if you make monthly payments on a four-year car loan, your loan has a total of 4 * 12 (or 48) payment periods. pval: Present value (or lump sum) that a series of payments to be paid in the future is worth now. For example, when you borrow money to buy a car, the loan amount is the present value to the lender of the monthly car payments you will make. fval: Future value or cash balance you want after you've made the final payment. The future value of a loan, for instance, is $0. As another example, if you will need $50,000 in 18 years to pay for your child's education, then $50,000 is the future value. duepay: Number indicating when payments are due. Use 0 if payments are due at the end of the payment period, and use 1 if payments are due at the beginning of the period. For our purposes, we will code: Irate = Val(Left$(CboInterest.Text , Len(CboInterest.Text)-1))/ 1200 (we divide by 1200 to get a monthly rate) Numper = LstTerm.Text * 12 (number of payments) Pval = TxtPrin.Text Fval = 0 DuePay = 0 LblPay.Caption = Pmt(Irate, Numper, Pval, Fval, DuePay) LblPay.Caption = Format(Lblpay.Caption, “currency”) That first line looks complicated because VB5.0 makes certain assumptions about variable declarations. Basically, VB50 doesn''t like that cbointerest.text has a % on the end. That len(cbointerest.text)-1 removes the %. The Val(Left$ (cbointerest.text.....) is used to transform cbointerest.text from an alphanumeric to a number so we can do division.
Thus "8.05%" becomes 8.05
In reality, we want this to be .0805
Thus we divide by 1200 to get a monthly interest rate

We are going to be using a new function called VAL Syntax: Val(stringexpression) Remarks: The argument stringexpression is a sequence of characters that can be interpreted as a numeric value. The Val function stops reading the string at the first character that it cannot recognize as part of a number. Val also strips blanks, tabs, and line feeds from the argument string. For example, the following returns the value 1615198: Val(" 1615 198th LOAD EVENT FOR THE FRMPAY.FRM We need to add items to the list box and combo box when the form is loaded. Additem is a visual basic command. The listindex puts the cursor on the nth+1 item on the list. (Here is will default to 5 year loan) Sub Form_Load () LstTerm.AddItem "1" LstTerm.AddItem "2" LstTerm.AddItem "3" LstTerm.AddItem "4" LstTerm.AddItem "5" LstTerm.ListIndex = 4 For IntRate = .05 To .121 Step .005 CboInterest.AddItem Format(IntRate, "percent") Next IntRate End Sub EXPLAINING A FOR-TO-STEP-NEXT STATEMENT For IntRate = .05 To .121 Step .005 CboInterest.AddItem Format(IntRate, "percent") Next IntRate FOR VARIABLE = (Starting value) TO (Ending Value) STEP (Incrementing by this number) Perform the code you put in here the number of times specified on the FOR NEXT VARIABLE INTRATE CBOINTEREST.ADDITEM DISPLAYED .050 CboInterest.AddItem Format(.050 “percent) 5.00% .055 CboInterest.AddItem Format(.055, “percent) 5.50% .060 CboInterest.AddItem Format(.060, “percent) 6.00% .065 CboInterest.AddItem Format(.065, “percent) 6.50% .070 CboInterest.AddItem Format(.070, “percent) 7.00% .075 CboInterest.AddItem Format(.075, “percent) 7.50% .080 CboInterest.AddItem Format(.080, “percent) 8.00% .085 CboInterest.AddItem Format(.085, “percent) 8.50% .090 CboInterest.AddItem Format(.090, “percent) 9.00% .095 CboInterest.AddItem Format(.095, “percent) 9.50% .100 CboInterest.AddItem Format(.100, “percent) 10.00% .105 CboInterest.AddItem Format(.105, “percent) 10.50% .110 CboInterest.AddItem Format(.110, “percent) 11.00% .115 CboInterest.AddItem Format(.115, “percent) 11.500% .120 CboInterest.AddItem Format(.120, “percent) 12.00% If the user hits the EXIT button, we want to show the title form and hide the pay form: FrmTitle.Show FrmPay.Hide We also want the textbox for the principle be equal to the scroll bar value, regardless of which object the user uses: TxtPrin.Text = HsbPrin.Value This will be typed in twice for the horizontal scroll bar under the procs change and scroll: Sub HsbPrin_Change TxtPrin.Text = HsbPrin.Value End Sub Sub HsbPrin_Scroll. TxtPrin.Text = HsbPrin.Value End Sub Be sure to save your form as FRMPAY.FRM