Validation Functions for Data Fields

Field validation functions for data fields must accept three parameters. The first parameter points to the edit buffer for the field and is of type UCHAR *. The edit buffer contains an exact copy of the field contents (including protected characters). The second parameter points to the picture string for the field. The third parameter points to the form currently being processed.

Do not change the contents of the edit buffer or the picture string.

The edit buffer contains exactly the string that is in the field, including any protected characters. For numeric fields, this string is a string representation of the number. This string may not be the most useful information for your validation function. For example, to validate a numeric field, you may wish to have a numeric value instead of a string representation. To get the converted value of a data field, you should call the functions fld_get() or srf_get(), as described later in this chapter.

Caution: do not attempt to use the underlying data variable as the value of the field contents. The data variable is not updated until after field validation is successfully completed. Even if the FORCECONVERT field option is ON for the field, the data variable is not updated until after the validation function(s) and end-field function are called.

The call for a user validation function for a data field is as follows:

int vf_user(editbufp, picp, dfmp)
 
UCHAR *editbufp;
/* Pointer to the edit buffer 
*/
UCHAR *picp;
/* Pointer to picture for field
*/
DFORMPTR dfmp;
/* Pointer to processed form
*/

Your validation function should return a TRUE if the field is valid. If the field is not valid, your function should return FALSE and set the value of the global variable VAL_ERR to an appropriate value.

VAL_ERR is the global validation error variable. If VAL_ERR is set to a non-zero value, Vermont Views displays the error window and prints the appropriate error message. You can use one of the system error messages in your validation function, or you can create your own validation error message. You will find more information on using the validation error messages and creating your own messages later in this chapter.


Home Contents Previous Next