任何人都可以帮助我了解如何使用Progress 4gl框架显示以下图案:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5.
我试过这样的话:
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.
/ *显示答案时会被覆盖,如何并排显示答案? * /
答案 0 :(得分:3)
如果您将输出发送到文件,可以这样做:
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.
使用DISPLAY和FRAME与文本文件或打印机不同。当您创建一个框架并在其中显示“A”时,您将定义一个将显示该变量的位置。
每次您显示A时,该值将被置于相同的位置。
你可以把它变成一个DOWN框架并随着外循环的每次迭代移动到一个新的行,但你仍然只有每行一个位置。
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.
要拥有多个位置,您需要多个变量或数组,或者您可以构建一个字符串(doydoy44的解决方案)。这是一个带数组的例子:
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 :(得分:1)
我不明白这是什么问题 可能这可以帮到你:
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.
答案 2 :(得分:1)
您所谈论的行为就是我所说的向下框架。 ABL会自动为任何输出创建一个帧,如果要显示一个表中的一系列记录,它就会知道该帧是一个向下的帧,例如:
for each customer no-lock:
display customer.
end.
但在您的示例中,您并未使用for each
。要获得向下框架行为,您必须自己实现它。
以下是最简单的代码:
def var v-i as int no-undo.
do v-i = 1 to 10 with down:
display v-i.
down.
end.
然而,如果你把事情进一步说清楚的话,它实际上更清楚了。让我们定义一个命名框架,使其成为一个向下框架,然后使用它:
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.
如果你输出的东西,我几乎总是值得定义一个框架,我发现。
答案 3 :(得分:-1)
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.