Kbase 16536: How to clear an entire SELECTION-LIST.
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/05/1998 |
|
How to clear an entire SELECTION-LIST.
How to clear all itmes from a selection-list: |
============================================
The first idea that comes to mind for deleting an entire
selection list might look something like this:
DEFINE VARIABLE dummy AS LOGICAL.
DEFINE VARIABLE ItemCount AS INTEGER.
DEFINE VARIABLE I AS INTEGER.
ItemCount = SELECT-LIST:NUM-ITEMS.
DO I = 1 TO ItemCount:
dummy = SELECT-LIST:DELETE(I).
END.
Usually this kind of technique works fine. However, in the
case of selection lists it doesn't. The end result is that
only half of the list is deleted.
The reason why is that the selection list is dynamically
renumbered as items are deleted. So, for every iteration
of the DO loop the total number of items is reduced by 1.
At the same time the loop counter is incremented by 1.
Eventually, the loop counter ends being larger than the
number of items in the list and, at this point, no more
items are deleted.
For example, if you have have 5 items in a list you would
see results such as this:
Loop Iteration Selection list items Item to delete
-------------- -------------------- --------------
1 1, 2, 3, 4, 5 5
2 1, 2, 3, 4 2
3 1, 2, 3 3
4 1, 2 4
5 1, 2 5
As you can see, the end result is that the last two items,
which are now numered 1 and 2, are not deleted.
The way to work around this is to always delete item number 1.
This way, as the items are renumbered, the first one in the
list is always deleted until there are no items left. The
replacement code for the above example would be:
DO I = 1 to ItemCount:
dummy = SELECT-LIST:DELETE(1).
END.
Progress Software Technical Support Note # 16536