6. Validation Routines


General Description

At this point we throw in a couple of general purpose routines. The first should really be included in 'menu' driven programmes. The routine 'gets' a single character, validates it using the INSTR function and returns a value in RESULT or the flags YES and NO. The second should be used whenever there is doubt about whether a critical data entry is in upper or lower case. Any routine that you write which searches for matches between program data and keyboard entry should use such a routine at some point.
   In the first routines, the delete key has not been enabled and so, for instance, should you have a menu of 10 choices (0-9), you will have to call the routine twice: firstly to get the character 0-9, secondly to ask whether the entry is correctly returning the flags YES and NO.
   The first routine is called with two parameters, the first indicating what has to be validated, and the second the number of characters that MUST be entered from the keyboard.

Detailed Description

PROCvalidate

   Lines 1000-1120 This initialises variables inside the routine and defines the various things that Check$ can be. In the example I have chosen 'Y/N' answers, digits 0-9 and a hexadecimal entry, but if your menu only had three choices you would simply add 'Check$' = '123':GOTO 1130.
   1130-1210 This simply GET's the required characters, checks them with INSTR and leaves the result in B$. If you wish to exit on a Carriage Return this must be specified in Check$.
   1220-1250 If you use EVAL in conjunction with this routine, you will need a condition such as that in 1220. It does, of course, not matter that RESULT will pass a value 0 out if the routine is testing for (Y/N), and vice-versa.
   The RUNS are included for your convenience. Note in line 190 that you must have RESULT > 0 if you wish to use it subsequently in an ON GOTO.

FNconvert(A$)

Little to add here except that it is a nice example to use with computer studies pupils on how a string function can return a value. If you wish to change from upper case to lower case, 1095 and 1100 must be changed accordingly to Z=Y+32 and IF Y>64 AND Y<91 THEN Y=Z.