Back

Tip 29. Improving the Standard Validation Messages.

Some users get confused by the default validation message

DataWindow - d_customers
   Item 'xyz' does not pass validation test


A much more friendly message would be something like this.

DataWindow Error
   Value for Mark Up is not a valid Number.
   Please Try Again or Press 'Esc' to return to previous value.


If the tag value is blank then the column name is displayed.
It would be quite a task to update all the validation rules on all your datawindows. The following function is can be added to an anchestor datawindow control it is then called as the control is contructed. The tag value is used if it has been set otherwise the column name is displayed.

//---------------------------------------------------------------------------
//  Event Name : contructor
//     Purpose : Set Validation Messages
//        Sets : None
//---------------------------------------------------------------------------
            // Post as it is a low priority process
POST uf_set_validation_messages()

//---------------------------------------------------------------------------
//  Function Name : uf_set_validation_messages
//     Parameters : None
//        Purpose : Set Validation Messages
//        Returns : Success (0/1)
//           Sets : None
//---------------------------------------------------------------------------

string ls_col_name, ls_col_tag, ls_col_type, ls_typedesc, ls_message, ls_column_id
Long ll_index, ll_tab_sequence

IF NOT IsValid(this) THEN
   RETURN 0
END IF

            // Traverse dw's columns making each validation error message
            // more user-friendly.
FOR ll_index=1 TO Long(Describe("Datawindow.Column.Count"))
            // Low priority task. Yield to any other processes.
   Yield()

            // Check object still exists as the window could be
            // closed before the loop completes
   IF NOT IsValid(this) THEN
      EXIT
   END IF

   ls_column_id = "#" + String(ll_index)

   ll_tab_sequence = Long(Describe(ls_column_id + ".TabSequence"))
   IF ll_tab_sequence = 0 THEN
            // Do not need to change validation message of a non-editable field.
      CONTINUE
   END IF

            // Get Column Details
   ls_col_name = Describe(ls_column_id + ".Name")
   ls_col_tag  = Describe(ls_column_id + ".Tag")
   ls_col_type = Describe(ls_column_id + ".ColType")

   
            // Set Data Type Name         
   CHOOSE CASE Upper(Left(ls_col_type, 5))
      CASE 'CHAR('
         ls_typedesc = 'String'
      CASE 'DATE'
         ls_typedesc = 'Date'
      CASE 'DATET'
         ls_typedesc = 'Date & Time'
      CASE 'DECIM', 'NUMBE'
         ls_typedesc = 'Number'
      CASE 'TIME', 'TIMES'
         ls_typedesc = 'Time'
   END CHOOSE

            // Calculate new validation message.
   ls_message = "Value for "
   
   IF Len(ls_col_tag) > 0 THEN
      ls_message += ls_col_tag
   ELSEIF Len(ls_col_name) > 0 THEN
      ls_message += ls_col_name
   ELSE
      ls_message += 'an unknown field'
   END IF
      
   IF Len(ls_typedesc) > 0 THEN
      ls_message += " is not a valid " + ls_typedesc + "."
   ELSE
      ls_message += " is not valid."
   END IF
   
   ls_message += "~n~nPlease Try Again or Press ~~'Esc~~' to return to previous value."
   
            // Set column's new validation message.
   Modify(ls_column_id + ".ValidationMsg='" + ls_message + "'")
NEXT

RETURN 1
See Also Context Sensitive Micro Help for Datawindows.

Added before 01 Jan 2000

Back