** 1 page regular / 693 words ** Basic BASIC! If I said the date was 11199, does this mean the date is 11/01/1999 or 01/11/1999? Paul Jones explains validation and why it's needed... 110199? When a user enters data into the computer it has no idea whether the data makes sense or not. Data entry checking, called validation, is the responsibility of programs and can be used to check user entered data contains "sensible" values. For example, if a program is expecting a number all text characters entered can be rejected. You can program your own routines to do this, but ENCHANT, the commercial HiSoft BASIC enhancement, includes validation routines of its own. I shall be explaining some of these functions, which are included on the Reader Disk. If you find these useful, there are many more included with the full ENCHANT release. ** ENCHANT.JPG here ** There are numerous validation checks that can be performed on data, including: ** UL ** * Presence: Check the data actually exists. * Count: Check the data is a specific length. * Format: Check the data is correctly formatted (for example, postcode handling). * Range: Checks the data falls within a specific range. * Check digit: A customer ID is assigned an extra number generated from the ID which can be used to ensure the data is correctly entered. * Date checks, number checks and so on... ** /UL ** Let's briefly go through each check using the following example. Let's imagine I've got a form dialog which has inputs for the date (stored in dat$) and the customer ID (stored in cid$). The user enters the date as 12/02/1999 and the customer ID as 123L. ** NP ** valid_presence (txt$) ** /NP ** This check can be used on both data inputs to make sure both sets of data exist. If the check returns 1 the check is valid. Replace txt$ with the text that you wish to check. ** NP ** valid_count (txt$,l) ** /NP ** Checks to see if the text in text$ is of length l. The date must contain exactly 10 characters with exactly four characters in the customer ID. If valid_count (dat$,10)=1 then the date is valid and if valid_count (cid$,4)=1 then the customer ID is also valid. ** NP ** valid_format (txt$,code$) ** /NP ** A very useful check to see if the data is in a specific order. The code$ is a string character which is a template indicating the data format. For example, for our date string, the code must be NN/NN/NNNN where N represents a number. The Customer ID template is NNNL, where N represents a number and L represents a letter. ** NP ** valid_range (num,r1,r2) ** /NP ** The first three numbers of the customer ID must be in the range 1 and 999. The date can obviously be checked to see if there is the correct number of days in the month, whether the month is out of range or the year a leap year. ENCHANT includes a check to do this but we'll ignore that for this example. ** NP ** valid_digit (va,chk,bse) ** /NP ** Only applicable to the customer ID. The L in the example is the check digit which was generated by entering 123 as the real customer number. For example, if the customer ID was entered as 132L, the computer take the 132 and enters this as va in the above function, along with 135 for chk (check digit) and 11 for bse. Adding this to 65 and doing a chr$ of this result (to get a letter) returns C. L and C are the then compared and if they do not match, the customer number has been typed in wrongly. 011199? How's this related to PDO? Our registration creator was a little bugged, entering a name less than a certain amount of characters would crash the program. Validation can be used to check the lengths of characters and their format. This is especially true when typing in some our printer options in following months. These routines can also be used in your own programs to ensure data is being entered correctly. ** boxout ** Contact Paul can be contacted at: Email: Paul.jones31@virgin.net http://vzone.virgin.net/paul.jones31/ ** /boxout **