Progress Programming Tips
By Rod Gaither (rdg@worldinfo.com)
PPT-24 Character string lists
Tip:
When you need an unknown quantity but small number of variables
you can take the string list approach. This approach uses a
character variable and packs multiple items into it using a
delimiter. Progress provides several functions and statements to aid
in using this flexible (if not fast) data structure.
ENTRY - Returns the element in the list by number (Function)
- Replaces an element in the list by number (Statement)
LOOKUP - Locates an element and returns its number
CAN-DO - Checks for existence of element in the list
+ ... - String concatenation and other string handling statements
Many of these string list oriented activities now take an
additional parameter to specify the delimiter. This is great for
parsing input from external sources or allowing multiple layers within
a single string list.
The selection list and combo-box widgets take a string list to
manage the list of items. As such you often have the need to
keep a matching list of record references. This can be
accomplished by keeping a second string list, in the same
sequence, of the record keys.
Sample - (Imaginary State table)
---- Code insert begins ----
DEF VAR t-state-keys AS CHAR NO-UNDO.
DEF VAR t-state-list AS CHAR NO-UNDO.
DEF VAR t-current-id AS INT NO-UNDO.
DEF VAR t-pos AS INT NO-UNDO.
FOR EACH State NO-LOCK:
ASSIGN
t-state-keys = t-state-keys + MIN(",",t-state-keys)
+ STRING(State.IDNum)
t-state-list = t-state-list + MIN(",",t-state-list)
+ State.Abbrv.
END.
/** To return the ID for a selected entry **/
ASSIGN
t-pos = LOOKUP("NC",t-state-list)
t-current-id = (IF t-pos > 0 AND t-pos < NUM-ENTRIES(t-state-keys)
THEN INT(ENTRY(t-pos,t-state-keys))
ELSE ?).
---- Code insert ends ----
The two disadvantages are the speed of string operations and
the requirement to convert values to and from strings.
Wisdom:
Beware the cut and paste monster, not only is it the source of
insidious bugs but can lead to code explosion.
Rod Gaither | rdg@worldinfo.com
World Information Systems | (910) 333-2580 Voice
Greensboro, NC | (910) 333-2584 Fax