Progress
Language Tutorial
for Character


Working with Widget Values

There is one very important case when you want to make a distinction between the field a widget represents and the widget itself. When you display a value and enable a widget for input, the value in the field and in the widget are the same. From that point forward, however, the user can change the value in the widget, which is also known as the screen value.

When users manipulate screen values, they are not manipulating the underlying field or variable values. Your code has to explicitly assign changes in the widget to the field or variable. There are two ways to do this.

  1. Use the ASSIGN statement as shown in this code example:
  2. ASSIGN Variable1 Field1. 
    

    This form of the ASSIGN statement can be interpreted as “write the screen values of these widgets to their associated fields or variables.”

  3. Access the SCREEN-VALUE attribute as shown in this code example:
  4. Field1 = INTEGER(Variable1:SCREEN-VALUE) + 200. 
    

Notice the use of the INTEGER data conversion function. No matter what data type the underlying field or variable may be, the screen value is always of type CHARACTER. Assuming that Variable1 is an integer variable, you need to use the appropriate data conversion function to make the expression compatible.

Checking for Changed Values

When you save screen values, it may be useful to check and see if the values have changed since you enabled the widgets. This check saves your application from doing unnecessary work. All data widgets have the MODIFIED attribute. MODIFIED is a LOGICAL attribute that contains a TRUE value if the value of the widget has changed since it was last enabled. Therefore, you can check to see if a value has changed before writing, as shown below:

IF Field1:MODIFIED THEN
    ASSIGN Field1. 

Validating Input

You saw earlier that the format phrase has a VALIDATE option. You can use this option to establish validation criteria for variables or to change default validation for database fields. Although you can use this option instead of the corresponding Data Dictionary properties, it is far more valuable to use the Data Dictionary as a central source for validation information.

To use the VALIDATE option, specify a condition and a message expression, as shown in this example:

DEFINE FRAME Frame1
    Var1 VALIDATE(Var1 > 0, "Entry must be greater than zero.")
        WITH SIDE-LABELS 

Programming Example

This programming example demonstrates the techniques discussed in this section:

  1. Open lt-07-03.p and run it. The following display appears:
  2. Type a new value for CharField that does not begin with the letter “A.”
  3. Try to move input focus with TAB or the mouse. An alert box appears telling you that the entry must begin with the letter “A.”
  4. Choose OK. You return to the main display with input focus on CharField. You cannot move from this field until you make a valid entry.
  5. Type a new value for CharField that does begin with “A” and move input focus. This time you can.
  6. Try the same experiment with IntField using a number less than 100.
  7. Now that you have changed the screen values, choose Reset. The original values appear.
  8. Type new valid entries in the fields and choose Save and then Reset. As you can see, your new values are now also the values stored in the variables.
  9. Choose Exit and press SPACEBAR to return to the Procedure Editor.

Here is the code for this example:

lt-07-03.p
      /**********  DEFINE WIDGETS  **********/
      DEFINE VARIABLE CharField AS CHARACTER INITIAL "A string". 
      DEFINE VARIABLE IntField AS INTEGER INITIAL 200.
      DEFINE BUTTON btn-Save LABEL "Save".
      DEFINE BUTTON btn-Reset LABEL "Reset".
      DEFINE BUTTON btn-Exit LABEL "Exit". 
      /********** DEFINE FRAMES  **********/
      DEFINE FRAME Frame1
/*1*/      SKIP(2) CharField COLON 10 VALIDATE( CharField BEGINS "a", 
             "Entry must begin with the letter A.") SKIP
/*2*/      IntField COLON 10 VALIDATE(IntField > 100, 
            "Entry must be greater than 100.") SKIP(1)
        btn-Save btn-Reset btn-Exit
            WITH NO-BOX CENTERED SIDE-LABELS THREE-D. 
      /**********  DEFINE TRIGGERS  **********/
/*3*/    ON CHOOSE OF btn-Save
       DO:
/*4*/      IF CharField:MODIFIED THEN
              ASSIGN CharField.
        IF IntField:MODIFIED THEN
              ASSIGN  IntField.
       END.
/*5*/  ON CHOOSE OF btn-Reset
       DO:
          DISPLAY CharField IntField WITH FRAME Frame1.
       END. 
      /**********  MAIN LOGIC  **********/
      DISPLAY CharField IntField WITH FRAME Frame1.
      ENABLE ALL WITH FRAME Frame1.
      WAIT-FOR CHOOSE OF btn-Exit. 

The following notes explain the code highlights:

  1. The VALIDATE option of the format phrase establishes a condition that will allow only input that begins with the letter “A.”
  2. Here the VALIDATE option establishes a condition that disallows input less than 100.
  3. This trigger moves the screen values into the associated variables.
  4. The IF statement checks the MODIFIED attribute of the widget to see if any changes were made, and thus whether it is necessary to write a new value.
  5. This trigger copies the values of the variables to the screen with the DISPLAY statement.

Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095