1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question Delete() In Combobox

Discussion in 'Development' started by grinder, Apr 18, 2017 at 8:42 AM.

  1. grinder

    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 (progress):
    1.   DO iCntr = 1 TO NUM-ENTRIES(cbPrinterList:LIST-ITEMS, ',':U):
    2.     IF SUBSTRING(ENTRY(iCntr,cbPrinterList:LIST-ITEMS,',':U),1,2) = '~\\':U THEN
    3.       cbPrinterList:DELETE(ENTRY(iCntr,cbPrinterList:LIST-ITEMS,',':U)).
    4.   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.
     
  2.  
  3. Cringer

    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.
     
    grinder likes this.
  4. Cringer

    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.
     
  5. grinder

    grinder Member

    Never thought of that, but it makes sense. Nevertheless it's weird :D
     
  6. Cringer

    Cringer ProgressTalk.com Moderator Staff Member

    Actually thinking about it you can probably do it like this with the delete:
    Code (progress):
    1.  
    2.   DO iCntr = NUM-ENTRIES(cbPrinterList:LIST-ITEMS, ',':U) TO 1 by -1:
    3.     IF SUBSTRING(ENTRY(iCntr,cbPrinterList:LIST-ITEMS,',':U),1,2) = '~\\':U THEN
    4.       cbPrinterList:DELETE(ENTRY(iCntr,cbPrinterList:LIST-ITEMS,',':U)).
    5.   END.
    6.  
    So essentially working backwards. That way if you delete an item you're not breaking the position of subsequent items.
     
    grinder likes this.
  7. grinder

    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.
     
    Cringer likes this.

Share This Page