Deleting Items from selection-list

make

Member
Hi peggers,

i have a little problem. Iam filled up a selection-list an want to delete all Items.

I tried with :

do i = 1 to fanlage:num-items :
fAnlage:delete(i).
end.


It works, but the first Item is still there .

Where ist my mistake ?

Greets

Make
 

Rafal

New Member
I had similar problem and now I use this to deleting items from selection-list
select-1:LIST-ITEMS = "".
I hope that my solution helps you.
Rafal
 
Refal's solution is definitely the most efficient, but I thought that I would explain why your code didn't work.

You wrote:

do i = 1 to fanlage:num-items :
fAnlage:delete(i).
end.



And there's a couple of things wrong.

Firstly, the NUM-ITEMS attribute will be evaluated on each iteration of the loop. Which means that the value changes each time. So because variable i is increasing and NUM-ITEMS is decreasing, the loops ends too soon.

Secondly, the method call fAnlage:delete(i) should read fAnlage:delete(1)because the index of the remaining items is changing at each iteration. So entry 2 becomes entry 1 when entry 1 is deleted, and so on.

To make your code work correctly, it would have to look like this:

j = fanlage:num-items.

do i = 1 to j :
fAnlage:delete(1).
end.


But this would work just as well:

do while fanlage:num-items > 0:
fAnlage:delete(1).
end.

But as I've said, stick with Rafal's solution.
 
Top