Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 239
Bill Avatar asked Apr 03 '12 13:04

Bill


2 Answers

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.
like image 180
Abe Voelker Avatar answered Sep 27 '22 23:09

Abe Voelker


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.
like image 39
Tim Kuehn Avatar answered Sep 27 '22 22:09

Tim Kuehn