Progress
Language Tutorial
for Windows
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.
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:
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:
Programming Example
This programming example demonstrates the techniques discussed in this section:
- Open
lt-07-03.p
and run it. The following display appears:
![]()
- Type a new value for CharField that does not begin with the letter “A.”
- 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.”
- 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.
- Type a new value for CharField that does begin with “A” and move input focus. This time you can.
- Try the same experiment with IntField using a number less than 100.
- Now that you have changed the screen values, choose Reset. The original values appear.
- 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.
- Choose Exit and press SPACEBAR to return to the Procedure Editor.
Here is the code for this example:
The following notes explain the code highlights:
- The VALIDATE option of the format phrase establishes a condition that will allow only input that begins with the letter “A.”
- Here the VALIDATE option establishes a condition that disallows input less than 100.
- This trigger moves the screen values into the associated variables.
- 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.
- 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 |