Resolved Delete() In Combobox

grinder

Member
Hi there,

I have a little problem with a combobox and I don't get it ^^

There's a combobox which is filled with a list of some printers, not SESSION:GET-PRINTERS(), just a comma-separated string, e.g. "printer01,printer02,printer03,printer04,printer05,printer06,printer07,printer08,printer09,\\server\printer01,\\server\printer02,\\server\printer03,\\server\printer04,\\server\printer05,\\server\printer06,\\server\printer07,\\server\printer08,\\server\printer09"

All I want to do is to remove the network-printers.

Code:
  DO iCntr = 1 TO NUM-ENTRIES(cbPrinterList:LIST-ITEMS, ',':U):
    IF SUBSTRING(ENTRY(iCntr,cbPrinterList:LIST-ITEMS,',':U),1,2) = '~\\':U THEN
      cbPrinterList:DELETE(ENTRY(iCntr,cbPrinterList:LIST-ITEMS,',':U)).
  END.

This works only for each second (?) network-printer in this list. If I run this a second time, each network-printer is removed. But I don't want to run this twice.
I'm pretty sure that it must be something with the backslashs (also tried with CHR(92)).



Thx in advance.....


PS: Progress 11.3.3 and Windows environment.
 

Cringer

ProgressTalk.com Moderator
Staff member
I think it's to do with the fact that you're deleting them as you iterate through, so entry 3 is deleted, then you move on to entry 4, but entry 4 is now entry 3 in the list. If that makes sense.
 

Cringer

ProgressTalk.com Moderator
Staff member
I would solve this by creating a new string for the list-items and then setting cbPrinterList:list-items to the new string, rather than using delete.
 

grinder

Member
I think it's to do with the fact that you're deleting them as you iterate through, so entry 3 is deleted, then you move on to entry 4, but entry 4 is now entry 3 in the list. If that makes sense.
Never thought of that, but it makes sense. Nevertheless it's weird :D
 

Cringer

ProgressTalk.com Moderator
Staff member
Actually thinking about it you can probably do it like this with the delete:
Code:
  DO iCntr = NUM-ENTRIES(cbPrinterList:LIST-ITEMS, ',':U) TO 1 by -1:
    IF SUBSTRING(ENTRY(iCntr,cbPrinterList:LIST-ITEMS,',':U),1,2) = '~\\':U THEN
      cbPrinterList:DELETE(ENTRY(iCntr,cbPrinterList:LIST-ITEMS,',':U)).
  END.

So essentially working backwards. That way if you delete an item you're not breaking the position of subsequent items.
 

grinder

Member
Thank you very much Cringer :) Simple idea, but I actually didn't think of going backwards through the list *thumbsup* Works like a charm.
 
Top