Announcement

Collapse
No announcement yet.

Creating Soft Edits

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating Soft Edits

    Creating Soft Edits

    Hard edits are when you set field properties to force a user to enter a value that is within a range, allowed values, etc. There may be times when you need the user to enter a value that is not within these parameters. The following example is a Soft edit, which will prompt the user that the value falls outside the parameter. This way, they are alerted to the error and can decide if it needs to be corrected. For this, we use the SAS MessageBox object. This code could be used in the onLostFocus, onEnter or onUpdate methods.

    Example
    Say we want to check that a numeric field must be between 1 and 10, but we want to allow for exceptions, the following process could be used:
    • Evaluate condition
    • Display message box to user
    • If the user responds 'No' then error the field
    • Otherwise, the user can continue without changing the value


    The code would look like this:

    Code:
    /** OnLostFocus Method **/                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                    
    %include objfile;                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                    
    _OnLostFocus: method _self_:u:object;                                                                                                                                                                                                                           
    link createobj;                                                                                                                                                                                                                                                 
    ************************;                                                                                                                                                                                                                                       
    ** Add user code here **;                                                                                                                                                                                                                                       
    ************************;                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                    
        if _self_.text > . and (_self_.text < 1 or _self_.text > 10) then do;                                                                                                                                                                                       
                                                                                                                                                                                                                                                                    
            ** first ask user if correct **;                                                                                                                                                                                                                        
            dcl char msg = 'Is the value specified ('||compress(_self_.text)||') valid?';                                                                                                                                                                           
            msglist={};                                                                                                                                                                                                                                             
            rc=insertc(msglist,msg,-1); rc=rc;                                                                                                                                                                                                                      
            dcl char rcc=messageBox(msglist,'?','YN','Question','N');                                                                                                                                                                                               
            msglist=dellist(msglist,'y');                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                    
            ** if no, the error field **;                                                                                                                                                                                                                           
            if rcc='NO' then do;                                                                                                                                                                                                                                    
                _self_._errorOn();                                                                                                                                                                                                                                  
                _self_.cpErrorMessage='Please specify a valid value.';                                                                                                                                                                                              
                return;                                                                                                                                                                                                                                             
            end;                                                                                                                                                                                                                                                    
        end;                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                    
    endmethod;
    The following is the resulting message box.

    Last edited by dkeesey; 07-14-2009, 02:23 PM.
Working...
X