0
votes

Can anyone help me understand how to display the following pattern using a Progress 4gl frame:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5.

I have tried like this:

DEFINE VARIABLE a AS INTEGER NO-UNDO.
DEFINE VARIABLE b AS INTEGER NO-UNDO.
DO
    a =1 TO 5 WITH FRAME f:
    DO
        b = 1 TO a WITH FRAME f:
        DISPLAY  a SPACE SKIP.
        PAUSE.
    END.
END. 

/* while displaying the answer is overwritten, how do I display the answer side by side? */

4
The output is exactly what I would expect from the given program, what else did you expect? - Erich Kitzmueller
The answer what I'm getting is 1 next line 2 nl 3nl 4 nl 5 . .I want side by side 2 two times 3 three times so on . . - chaitanya mutyala
Maybe you shouldn't name both frames f. (Just a wild guess from someone who doesn't know progress-4gl) - Erich Kitzmueller

4 Answers

3
votes

If you were sending your output to a file you could do it like this:

define variable a as integer no-undo.
define variable b as integer no-undo.

output to "output.txt".
do a = 1 to 5:
  do b = 1 to a:
    put b.
  end.
  put skip.
end.

output close.

Using DISPLAY and FRAME is not like text files or printers. When you create a frame and DISPLAY "A" in it you are defining a single position where the variable will be displayed.

Every time that you DISPLAY A the value will be placed in the same position.

You can make it a DOWN frame and move to a new line with each iteration of the outer loop but you will still only have one position per line.

define variable a as integer no-undo.
define variable b as integer no-undo.

do a = 1 to 5 with frame f:
  do b = 1 to a:
    display b with frame f.
  end.
  down with frame f.
end.

To have multiple positions you need multiple variables or an array or you can build a string (doydoy44's solution). Here is an example with an array:

define variable a as integer no-undo.
define variable b as integer no-undo.
define variable c as integer no-undo extent 5 format ">>>>".

do a = 1 to 5 with frame f:
  do b = 1 to a:
    c[b] = b.
  end.
  display c with frame f.
  down with frame f.
end
1
votes

I'm not sur to understand what is the problem.
May be this can help you:

DEFINE VARIABLE a AS INTEGER NO-UNDO.
DEFINE VARIABLE b AS INTEGER NO-UNDO.
DEFINE VARIABLE woutput AS CHARACTER  NO-UNDO.
DO
    a =1 TO 5 WITH FRAME f:

    woutput = "".
    DO 
        b = 1 TO a WITH FRAME f:
        woutput = woutput + " " + string(b).
    END.
    DISPLAY TRIM(woutput) SKIP .
    PAUSE.
END. 
1
votes

The behaviour you are talking about is what I call a down frame. ABL creates a frame automatically for any output, and if you are displaying a series of records from a table, it knows to make that frame a down frame, for example:

for each customer no-lock:
    display customer.
end.

But in your example you aren't using for each. To get the down frame behaviour you are going to have to make it happen yourself.

Here is the simplest code that will give you that:

def var v-i as int no-undo.

do v-i = 1 to 10 with down:
    display v-i.
    down.
end.

It's actually clearer what is going on, though, if you spell things out a bit further. Let's define a named frame, make it a down frame, and then use it:

def var v-i as int no-undo.

def frame f-x 
        v-i
    with down.

do v-i = 1 to 10:
    display v-i with frame f-x.
    down with frame f-x. 
end.

It's almost always worth defining a frame if you are outputting something, I find.

-1
votes
define variable a as int no-undo.                             
define variable b as int no-undo.                              
define variable res as char no-undo.  
               
update a.

b = 1.                  
repeat while(b <= a):

res = res + " " + string (b).               
   b = b + 1.                
   disp res format "x(20)".             
end.