Home Page

Previous Menu

Contact Us

Adding Error Messages and Traps (Clarion 5 ABC)

Code Supplied by Dennis E.Evans

Download the code

This template will allow you to add error traps and messages to selected fields on the update form.

The template generates if (field = data) type tests into the ValidateField method.   The other operators may be used. (<> <= >= etc) and   if not (test) may also be used.

The template will use the standard error messages or you may add your own.   If you use a custom error number be sure to use the GlobalErrors.AddError to add the error block.

Notes:  the value to test the field needs to be global or constant value of some kind.   If a variable is needed you will have to override the method and add the parameters as needed.

The template uses a prepare statement to fill a symbol with the error msg equate values from the AbError.inc file.  The template expects this file to be located in clarion5\libsrc\ directory.

The template will work with C5, C5a,C5b.  For C4 the prepare statement will need to be changed.

Usage,

  Register normally
  Add the template to the update form.
  Fill in the prompts.



#template(ValidSingleField, 'Add validation code to fields'),family('ABC')
#! -------------------------------------------------------------------------
#extension(FormFieldValidation, 'Validate Selected Fields On A Form'),PROCEDURE
#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
#! -------------------------------------------------------------------------
#PREPARE
  #DECLARE(%FileSpec)                    #! file name var
  #DECLARE(%Choices),MULTI               #! var to fill with the equates
#! Check the drive/path for the next line
  #SET(%FileSpec, 'C:\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
#! -------------------------------------------------------------------------
#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


Home Page

Previous Menu

Contact Us