#template(ValidSingleField, 'Add validation code to fields'),family('ABC') #! ------------------------------------------------------------------------- #! Freeware from Dennis E.Evans----------------- #! evansd@midamer.net------------------------------------------------------- #extension(FormFieldValidation, 'Validate Selected Fields On A Form'),PROCEDURE #! Check the drive/path of ABERROR.INC below ------------------------------ #PREPARE #DECLARE(%FileSpec) #! file name var #DECLARE(%Choices),MULTI #! var to fill with the equates #SET(%FileSpec, 'G:\CLARION5\LIBSRC\ABERROR.INC') #! assign the file #OPEN(%FileSpec),READ #! open the error inc read only #DECLARE(%LineRead) #! declare var to read into #READ(%LineRead) #! loop until eof #LOOP UNTIL (SUB(%LineRead, 1, 4) = 'None') #READ(%LineRead) #ENDLOOP #ADD(%Choices, 'Msg:' & SUB(%LineRead, 1, INSTRING(' ', %LineRead) - 1)) #READ(%LineRead) #! read the next line #LOOP UNTIL (%LineRead = ' END') #ADD(%Choices, 'Msg:' & SUB(%LineRead, 1, INSTRING(' ', %LineRead) -1)) #READ(%LineRead) #! read the next line #ENDLOOP #CLOSE(%FileSpec) #! close the file #ENDPREPARE #prompt('File', file),%ValidFileName,req #display('Fields to validate') #button('Fields to validate'),multi(%FieldsToValidate, %ValidateFieldName & '('& %ValidDuringNonStop &')' & '(' & %Condition & ')' & '('& %CompareField &')' & '(' & %NegExp & ')' & '('& %ErrorNumber &')' & '('& %ErrorNumberStr &')' & '('& %ThisErrorMessage &')'),INLINE #prompt('Field to validate', field),%ValidateFieldName #prompt('During non-stop select',check),%ValidDuringNonStop,default(%false) #prompt('Condition', drop('=|<<>|>|<<|>=|<<=')),%Condition,req #display('Enter a global variable or string to compare') #display('use single quotes for strings') #prompt('Compare Value', @s45),%CompareField,req #prompt('Place NOT before expresion',check),%NegExp,default(%False) #prompt('Standard Error Code ',from(%Choices)),%ErrorNumber,default('Msg:None') #enable(%ErrorNumber = 'Msg:None'),clear #prompt('Custom Error Code ', @s35),%ErrorNumberStr #prompt('Error message ', @s100),%ThisErrorMessage #display('(no quotes)') #endenable #endbutton #at(%ControlEventHandling),priority(5000) #IF(%ControlEvent = 'Accepted') #for(%FieldsToValidate) #if(%ValidateFieldName = %ControlUse) #find(%Field, %ControlUse) #if(%ValidDuringNonStop = %false) #insert(%AlwaysValidate) #else #insert(%ValidateFieldCode) #endif #endif #endfor #endif #endat #! ------------------------------------------------------------------------- #at(%FieldLevelValidation, %File),priority(6000) #for(%FieldsToValidate) #if(%ValidateFieldName = %Field) #if (%NegExp) if not (%ValidateFieldName %Condition %CompareField) #else if (%ValidateFieldName %Condition %CompareField) #endif #if(%ErrorNumber <> 'Msg:None') ReturnValue = GlobalErrors.Throw(%ErrorNumber) #else ReturnValue = GlobalErrors.ThrowMessage(%ErrorNumberStr,'%ThisErrorMessage') #endif end !if #endif #endfor #endat #! ------------------------------------------------------------------------- #group(%AlwaysValidate) if (0{prop:acceptall} = false) #insert(%ValidateFieldCode) end #! ------------------------------------------------------------------------- #group(%ValidateFieldCode) if Access:%ValidFileName.ValidateField(where(%FilePrefix:Record,%ValidateFieldName)) select(?) cycle end !if Access