Code Template: ControlValueValidation


Top  Previous  Next

The ControlValueValidation Code template performs data entry validation for an entry-type control (ENTRY, SPIN, or COMBO) by looking up the value entered by the user in another data file. If the lookup is successful, the entered value is valid. If not, it calls another procedure to allow the user to select a valid value from the lookup file. This Code template is designed to generate code only into EVENT:Selected or EVENT:Accepted embed points of an ENTRY, SPIN, or COMBO control. These are the controls into which a user can directly type in data.

#CODE(ControlValueValidation,'Control Value Validation')

 #RESTRICT

   #CASE(%ControlType)

   #OF('ENTRY')

   #OROF('SPIN')

   #OROF('COMBO')

     #CASE(%ControlEvent)

     #OF('Accepted')

     #OROF('Selected')

       #ACCEPT

     #ELSE

       #REJECT

     #ENDCASE

   #ELSE

     #REJECT

   #ENDCASE

 #ENDRESTRICT

#DISPLAY('This Code Template is used to perform a control value')

#DISPLAY('validation.  This Code Template only works for')

#DISPLAY('the Selected or Accepted Events for an Entry Control.')

#DISPLAY('')

#PROMPT('Lookup Key',KEY),%LookupKey,REQ

#PROMPT('Lookup Field',COMPONENT),%LookupField,REQ

#PROMPT('Lookup Procedure',PROCEDURE),%LookupProcedure

#DISPLAY('')

#DISPLAY('The Lookup Key is the key used to perform the value validation.')

#DISPLAY('If the Lookup Key is a multi-component key, you must insure that')

#DISPLAY('other key elements are primed BEFORE this Code Template is used.')

#DISPLAY('')

#DISPLAY('The Lookup field must be a component of the Lookup Key.  Before')

#DISPLAY('execution of the lookup code, this field will be assigned the value of')

#DISPLAY('the control being validated, and the control will be assigned the value')

#DISPLAY('of the lookup field if the Lookup procedure is successful.')

#DISPLAY('')

#DISPLAY('The Lookup Procedure is called to let the user to select a value. ')

#DISPLAY('Request upon entrance to the Lookup will be set to SelectRecord, and ')

#DISPLAY('successful completion is signalled when Response = RequestCompleted.')

#IF(%ControlEvent='Accepted')

IF %Control{PROP:Req} = False AND NOT %ControlUse #<! If not required and empty

ELSE

#INSERT(%CodeTPLValidationCode)

END

#ELSIF(%ControlEvent='Selected')

#INSERT(%CodeTPLValidationCode)

#ELSE

 #ERROR('This Code Template must be used for Accepted or Selected Events!')

#ENDIF

A Code template always starts with the #CODE statement, which identifies it within the template set and defines the description which appears in the list of available Code templates for a given embed point.

The #RESTRICT structure defines the embed points where the code template will appear as a choice. The #CASE(%ControlType) structure limits the embed points to the ENTRY, SPIN, and COMBO controls, and the #CASE(%ControlEvent) structure limits the embed points to EVENT:Accepted and EVENT:Selected.

The #ACCEPT statement indicates these are appropriate embed points, while the #REJECT indicates all other control type and event embed points are not valid for the Code template to appear in as a choice.

All the #DISPLAY statements display their text to the programmer on the code template's prompt dialog. These describe the information the programmer needs to supply in the prompts.

The first #PROMPT asks for the name of the key to use in the file that will be used to validate the user's input. The REQ attribute indicates the programmer must supply this information.

The second #PROMPT asks for the name of the field in the key that contains the same information the user should enter into the control. Again, the REQ attribute indicates the programmer must supply this information.

The third #PROMPT asks for the name of the procedure to call if the lookup is unsuccessful. This would usually be a Browse procedure for the lookup file with a Select button to allow the user to choose the record containing the value they want for the control.

Again, the #DISPLAY statements display text to the programmer on the prompt dialog to describe the information the programmer needs to supply in the prompts.

The #IF(%ControlEvent='Accepted') structure generates an IF structure for EVENT:Accepted that detects when the control has the REQ attribute or the user has entered a value and #INSERTs the %CodeTPLValidationCode #GROUP to generate the source code for the data validation. The #ELSIF just unconditionally #INSERTs the %CodeTPLValidationCode #GROUP to generate the source code for the data validation.

If the event is anything other than EVENT:Accepted or EVENT:Selected, an error message is the only output generated.

See Also:     %CodeTPLValidationCode #GROUP