Progress
Language Tutorial
for Windows
Using Variables
A variable is a temporary storage place for data. The value contained in a variable may change during the execution of the program that contains it. Typically, variables contain data from the user, copies of database fields or other variables, or the results of expressions.
Defining Variables
The partial syntax for the define statement below contains more options than you encountered in Chapter 3.
Table 5–1 describes the new syntax components of the DEFINE VARIABLE statement:.
Using LIKE
When defining a variable, you must specify either the data type or a database field or another variable whose format and attributes you want to copy to the new variable. When you specify the LIKE option, the new variable acquires the format, label, and initial value attributes of the referenced field or variable. You can override an inherited attribute by using the FORMAT, LABEL, and INITIAL options.
NOTE: To use a LIKE phrase that references a database field, you must be connected to the database that contains the field you want to copy.Examine the following code:
Here’s what happens:
- You create a variable to hold the name of a company.
- Your second variable is identical to the first; that is, New-Name2 has the same value, format, and label that you specified in the New-Name1 definition.
- In this statement, you create a third variable that inherits many of the attributes of a database field. Notice the general syntax for making a specific reference to a database field: table-name.field-name. The period separates the table and field names.
Using Arrays
Arrays are fields or variables that contain multiple data elements. The extent of an array is the number of elements it contains.
To define a field or variable as an array, specify the extent. If you want to define a database field as an array, use the extent option in the Data Dictionary. To define a variable as an array, use the EXTENT option in the DEFINE VARIABLE statement.
To initialize the array with values, you can use the INITIAL option with the values listed between square brackets as shown in the following code:
If you do not supply enough values to fill up the elements of the array, Progress copies the last specified value into the remaining elements of the array. If you supply too many values, Progress returns an error message.
Within a procedure, you can:
Follow these steps to see how to set up an array, present the whole array for user interaction, and reference the array in a trigger:
- Open
lt-05-01.p
and run it. The interface shown below appears:
![]()
The array of 12 elements contains the number of days in each month. Each element has an individual label that corresponds to the name of the month.
- Press TAB to move through the array elements. Notice the message area of the window. As you enter each element, the message references the label, data, and index of the element.
- Choose Exit, then press SPACEBAR to return to the Procedure Editor.
Here is the code that created the display:
NOTE: The THREE-D option is relevant only on a Windows client; it is ignored by a character client.These notes describe the array techniques used in this procedure:
- The DEFINE VARIABLE statement with the EXTENT option defines the array.
- To give each element an individual label, use a comma-separated list of strings after the LABEL keyword.
- To initialize the elements, use a bracketed, comma-separated list of values after the INITIAL keyword.
- An unsubscripted reference to an extent variable references all of the array elements. In a DEFINE FRAME statement, Progress includes room in the frame for each element of the array as a fill-in field.
When you use the COLON option of the format phrase, Progress positions the field by the colon that terminates the widget label. When used with an array, the COLON option stacks the elements neatly.
- Here, you use the array variable name (Months) as a reference to the whole array. If the user enters a fill-in field associated with any of the elements, the trigger executes.
- The SELF keyword is called a system handle. The LABEL, SCREEN-VALUE, and INDEX keywords are widget attributes. A system handle is a global variable that holds a widget handle. The system maintains system handles for you. SELF is a system handle that holds the widget handle of the current widget (a widget that has input focus or a widget for which a trigger is firing). SELF is a convenient way of referring to an individual array element without having to keep track of the index. You’ll learn more about SELF later in the tutorial.
The LABEL attribute holds the widget label. The SCREEN-VALUE attribute holds the value shown on the screen, which may not be the same as the value in the underlying variable. (Perhaps the user changed the screen value or the procedure changed the field value.) The tutorial covers screen values and field values more thoroughly later. Finally, the INDEX attribute holds the index value of the array element where the cursor currently resides. If you need to know explicitly where the cursor is, as opposed to relying on SELF, the INDEX attribute is your tool.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |