如何解决如何在未格式化的进行中使用 IF ELSE IF?
我遇到了一个程序问题,如果某个数据库字段具有特定值,我需要输出不同的字符串。
假设我有一个名为 TestDB
的数据库,其中包含以下字段 Name
、Age
、Currency
我将数据输出到 .csv 文件中,因此我的公司使用了大量 put unformatted
语句。
“输出”部分看起来像这样:
未格式化
TestDB.Name ';'
TestDB.Age ';'
如果 TestDB.Currency = 1 那么 'Euro' 否则? ';'
如果 TestDB.Currency = 2 那么 'Dollar' 否则? ';'
如果 TestDB.Currency = 3 那么 'Kuna' 否则? ';'
如果 TestDB.Currency = 4 那么 'Pound' else ?
跳过。
这些 if's
的问题是,如果 Currency 为 1,它将输出 Euro,但对于其他 if's
仍然输出?在 .csv 文件中。
我希望这些 if 的结构如下:if... else if... else if... else
因此,如果第一个 if 是正确的,则将跳过所有其他 if's
。
我尝试了多种方法,但每次都失败了。 有人可以帮我吗?
解决方法
我想你正在寻找这样的东西
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.
,
由于我怀疑任何人都希望将 1、2、3、4 视为货币,因此您可能已经拥有执行此转换的 function
或 method
。>
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
.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。