【问题标题】:Using frames in progress 4gl使用正在进行的帧 4gl
【发布时间】:2015-07-02 06:08:15
【问题描述】:

谁能帮助我了解如何使用 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. 

/* 显示答案时被覆盖,如何并排显示答案? */

【问题讨论】:

  • 输出正是我对给定程序的期望,您还期望什么?
  • 我得到的答案是 1 next line 2 nl 3nl 4 nl 5 。 .我要并排 2 两次 3 次 3 次等等。 .
  • 也许你不应该把两个框架都命名为f。 (只是一个不知道progress-4gl的人的疯狂猜测)

标签: progress-4gl openedge


【解决方案1】:

如果您要将输出发送到文件,您可以这样做:

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

【讨论】:

    【解决方案2】:

    我不明白是什么问题。
    也许这可以帮助你:

    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. 
    

    【讨论】:

      【解决方案3】:

      你所说的行为就是我所说的向下框架。 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.
      

      我发现,如果要输出某些内容,几乎总是值得定义一个框架。

      【讨论】:

        【解决方案4】:
        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.
        

        【讨论】:

        • 点评来源: S.O. 通常不欢迎纯代码的答案。社区。你能添加一些解释文本吗?
        猜你喜欢
        • 2013-12-01
        • 2020-12-25
        • 1970-01-01
        • 2021-10-19
        • 2021-05-30
        • 1970-01-01
        • 1970-01-01
        • 2015-08-03
        • 1970-01-01
        相关资源
        最近更新 更多