Related Information

See Chapter 23, "About Windows," for more information about creating windows. See Chapter 25, "Changing the Appearance of Windows," for more information about modifying the size, location, and other attributes of a window.

The tutorial program fm_validate.c demonstrates many of the topics covered in this chapter. A form with two fields, one for entering a letter grade and one for entering a numeric grade is created.

For the letter grade field, a range is specified from "A" to "F"; however, a letter grade of 'E' should not be entered. A field validation function no_e_func is installed for the field to catch this invalid response. no_e_func sets VAL_ERR to NO_E_GRADE if an "E" is entered in the field. NO_E_GRADE would be added to the end of the list of validation error codes in vv_form.h. A corresponding validation message would be added in the validation error message array in vv_valmsg.c that reads:

"E is not a valid letter grade."

For the numeric grade field, a range is specified of 0 to 100.

After the user exits the form, an installed form validation function ensures that the letter grade matches the numeric grade given by the user. The form validation function uses a structure installed in the user pointer of the form structure. This structure is initialized so as to give the range of numeric grades allowed for each letter grade.

The form validation function gets the number and letter grades entered by the user and compares them to make sure that the numeric grade falls within the allowed range for the letter grade. If it does not, the function sets VAL_ERR to NO_MATCH. NO_MATCH is a validation error code added to the list of validation error codes in vv_form.h. A corresponding validation message would be added in the validation error message array in vv_valmsg.c that reads:

"The letter grade does not match the number grade."

You should look at the source code for fm_validate.c, then compile, link, and run the program. You will need to add the necessary validation error messages to vv_valmsg.c (as noted here and in the comments of the program) to see the validation error messages when appropriate.


Home Contents Previous Next