running a loop on a comma delimited list of items progress 4GL

独自空忆成欢 提交于 2019-12-22 06:15:03

问题


def var cList as char no-undo.
assign cList = "one,two,three,four".
<Loop> cList
logic...
</Loop>

What's the best way to loop through a comma delimited list in a char variable so that in this example I would get one then two then three then four.


回答1:


Lol I still remember a bit of Progress I think.

DEF VAR i AS INT NO-UNDO.
&SCOPED-DEFINE LIST "one,two,three,four"

DO i=1 TO NUM-ENTRIES({&LIST}):
  MESSAGE SUBSTITUTE("LIST[&1] is &2", i, ENTRY(i, {&LIST})).
END.



回答2:


DEFINE VARIABLE ch-list     AS CHARACTER    NO-UNDO.
DEFINE VARIABLE i-cnt       AS INTEGER      NO-UNDO.
DEFINE VARIABLE i-entry     AS INTEGER      NO-UNDO.

ASSIGN
    ch-list = "one,two,three,four"
    .

ASSIGN
    i-cnt = NUM-ENTRIES(ch-list)
    .

REPEAT i-entry = 1 TO i-cnt:

    DISPLAY
        ENTRY(i-entry, ch-list)
        WITH DOWN.

END.



回答3:


 DEFINE VARIABLE iNumEntries AS INTEGER NO-UNDO.

 DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.

 def var cList as char no-undo.

 assign cList = "one,two,three,four".

 ASSIGN iNumEntries = NUM-ENTRIES(cList,",").

 DO iLoop = 1 TO iNumEntries:

      MESSAGE ENTRY(iLoop,cList,",") VIEW-AS ALERT-BOX.

      /* You can use display, assign to variable, etc */

 END.


来源:https://stackoverflow.com/questions/9994424/running-a-loop-on-a-comma-delimited-list-of-items-progress-4gl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!