Program 2:
Mortgage Problem w/ Error Checking


Modify the program developed in the last assignment to incorporate error checking.

There are two places where you should check for errors:

  1. in user  input, and
  2. prior to doing calculations. 

If there is an error in any of the user input you force the user to re-enter the data and you bypass both reading values from the form into variables and performing calculations.  If there is an error in any of the data used in a calculation you react by warning the user and continuing with the calculations if the data is merely questionable, or by using an alternative set of calculations if the data is unusable.


Errors in User Input:

For example, if a user fails to enter a value in a field (i.e., Text property is equal to "") but still hits the calculate button, display a message box on the screen asking them to provide the required input and return the focus to the unfilled text box using the Focus method.  You can obtain the value entered in a text box by using the Val function.  

Another error that you should detect is string data rather than numeric data.  For example, if the user enters "Sixty Thousand" into the Loan Amount field you should detect that by using the IsNumeric function and forcing them to re-enter the data.

Further, a loan amount, percent rate, or loan duration that is negative is also invalid and must be detected. 

Note that in this particular implementation the loan duration must be an integer number, so your program should detect invalid entries such as a 0.75 year loan duration.

This next part is more difficult.  The calculations on which this program is based require that the user enter an interest rate in the form 12 rather than 0.12.  You can handle this by checking to be sure that the interest rate is an integer or greater than 1, but that limits the program's usability.  That approach prevents the program from calculating a loan based on 0% interest rate or an interest rate like 12.5%.  A better solution is to generate an error and force the user to re-enter the value if the interest rate is negative, and to simply detect a non-integer interest rate and warn the user of a potential problem without forcing them to re-enter anything.  Check how your program reacts to such issues as a 0.25% rate, a 0% rate, percentage rates such as 12.5% rates, etc.  Compare your program to the demo, and be sure to note the difference between message boxes that display an error and those that display a warning.  Your message boxes should resemble those in the demo.


Errors in Calculations:

One of the basic problems that you look for when writing error checking routines is conditions that can adversely affect mathematical calculations. One of the most obvious is divide by zero. As you recall from your basic Math days, you can't divide by zero. Our first step is to look closely at our calculations to see if any of them offer the potential for a divide by zero condition. In the mortgage program there are two places where division takes place, and both must be examined to insure that a divide by zero does not occur. 


At the very least, include the following error checking:

Check each field to be sure that a value has been entered.
Check each field to be sure that a numeric value has been entered.
Check each field to be sure that a negative value has not been entered or, in the case of the loan duration, that an integer value greater than 1 has been entered.  Here are some sample tests for an integer:
  1. If (num - (num \ 1)) = 0 Then    'it is an integer
  2. If ((num / 1) = (num \ 1)) Then  'it is an integer
  3. If (Int(num) = num) Then          'it is an integer
Check to be sure that all formulas result in valid values, i.e., check for potential problems like division by zero.

Sample frmMortgage:


Refer to the sample solution for Program 1 for proper program formatting.