【问题标题】:How to use IF ELSE IF in put unformatted in Progress?如何在未格式化的进程中使用 IF ELSE IF?
【发布时间】:2021-06-26 18:34:37
【问题描述】:

如果某个数据库字段具有特定值,我需要输出不同的字符串。

假设我有一个名为 TestDB 的数据库,其中包含以下字段 NameAgeCurrency

我正在将数据输出到一个 .csv 文件中,因此我的公司使用了很多 put unformatted 语句。

“输出”部分看起来像这样:

不格式化

TestDB.Name ';'
TestDB.Age ';'
如果 TestDB.Currency = 1 那么 'Euro' 其他? ';'
如果 TestDB.Currency = 2 那么 'Dollar' 其他? ';'
如果 TestDB.Currency = 3 那么 'Kuna' 其他? ';'
if TestDB.Currency = 4 then 'Pound' else ?
跳过。

这些if's的问题是,如果货币为1,它会输出欧元,但对于其他if's仍然输出?在 .csv 文件中。 我希望这些 if 的结构如下:if... else if... else if... else 因此,如果第一个 if 是正确的,那么所有其他 if's 将被跳过。

我尝试了多种方法,但每次都失败了。 有人可以帮帮我吗?

【问题讨论】:

    标签: openedge progress-4gl


    【解决方案1】:

    我认为您正在寻找类似的东西

    if TestDB.Currency = 1 then 'Euro' 
    else if TestDB.Currency = 2 then 'Dollar' 
    else if TestDB.Currency = 3 then 'Kuna'
    else if TestDB.Currency = 4 then 'Pound' 
    else ?
    

    但是CASE 语句在这里可能更有效

    case TestDB.Currency:
      when 1 then curName = 'Euro'.
      when 2 then curName = 'Dollar'.
      when 3 then curName = 'Kona'.
      when 4 then curName = 'Pound'.
      otherwise curName = 'unknown'.
    end case.
    put unformatted curName skip.
    

    【讨论】:

    • 那个案例陈述实际上帮了我很多忙!非常感谢!它完美无瑕,该死的。我从来没有想过我可以在 put unformatted 之前使用 CASE 语句,然后在 put unformatted 中输出变量。
    【解决方案2】:

    由于我怀疑任何人希望将 1、2、3、4 视为货币,您可能已经拥有执行此转换的 functionmethod

    class env.currency:
    
       method static character getName (
          i_icurrency as integer
       ):
    
          case i_icurrency:
             when 1 then return 'Euro'.
             when 2 then return 'Dollar'.
             when 3 then return 'Kuna'.
             when 4 then return 'Pound'.
          end case.
    
          return 'unknown'.
    
       end method.
    
    end class.
    

    并在使用中:

    put unformatted
       TestDB.Name ';'
       TestDB.Age ';'
       env.currency:getName( TestDB.Currency ) ';'
    
       skip
       .
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-25
      • 1970-01-01
      • 2015-09-27
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多