Mortgage repayments are an important element of many peoples' lives. These need to be paid every month for long periods of time (perhaps for 20 or 30 years). However, the fact that a mortgage is an example of a compound interest loan make the monthly repayments rather difficult to calculate, as discussed in A Simple Home Mortgage Calculator. Fortunately, the article also shows that the calculation can be made easier by using:
- a standard formula for calculating the monthly repayments for a mortgage
- some simple VBScript code to run the calculation
This means, of course, that the VBScript developer can easily create an application that includes a mortgage calculator that will calculate the monthly repayment for any mortgage given:
- the initial amount borrowed
- the interest rate
- the time for which the mortgage is to run
The first step is, therefore, to create a function that will calculate the monthly payment.
A VBScript Mortgage Calculator Function
The key function for a VBScript mortgage calculator will return the monthly amount expected. It will have 3 inputs:
- the size of the loan
- the interest rate for the mortgage
- the number of years over which the mortgage is to be repaid.
This function is:
This can then be called from the script by using something like:
If the script is run then it will return the value $584.59 (as shown in figure 1). However, the developer will not want their users modifying the script, and so the next stage is to produce a simple user interface.
A VBScript Mortgage Calculator Function User Interface
The user interface will:
- read lines from the standard input to obtain the inputs for the formula
- calculate the monthly payments according to the inputs
- return the result to the user
For example:
This will not run by default, and so the following will need to be added to the script:
The application user can then use the cscript command to run the application from the Windows prompt (as shown in figure 2), and the programmer can now pass their mortgage calculator on to anyone with a Windows computer.