如果然后如何使用在水晶报告公式中构建一个字符串

时间:2021-03-16 22:31:04

This is Crystal Reports 9 in Visual Studio 2003 by the way

顺便说一句,这是Visual Studio 2003中的Crystal Reports 9

Simple question about crystal reports formula syntax: How do I build the formula's result using if then clauses?

关于水晶报告公式语法的简单问题:如何使用if then子句构建公式的结果?

Specifically I would like something like this:

具体来说,我想要这样的事情:

dim val as string
val = {table.level}
if {table.uom_id} = 5 then 
  val = val & ' feet'
else
  val = val $ ' meters'
end if

and val should be the result of the formula.

和val应该是公式的结果。

As long as we're at it, are there any shortcuts for writing these? These are horribly verbose, the ternary operator would be very welcome.

只要我们在这里,有没有写这些的快捷方式?这些非常冗长,三元运算符将非常受欢迎。

1 个解决方案

#1


18  

Your example is close. Just use Crystal syntax, as shown here:

你的例子很接近。只需使用Crystal语法,如下所示:

stringvar val := {table.level};

if {table.uom_id} = 5 then
  val := val + ' feet'
else
  val := val + ' meters';

//to return a value, just plop it down at the end
val

But if you want something a little more concise, use this:

但如果你想要更简洁的东西,请使用:

if {table.uom_id} = 5 then
  {table.level} + ' feet'
else
  {table.level} + ' meters';

#1


18  

Your example is close. Just use Crystal syntax, as shown here:

你的例子很接近。只需使用Crystal语法,如下所示:

stringvar val := {table.level};

if {table.uom_id} = 5 then
  val := val + ' feet'
else
  val := val + ' meters';

//to return a value, just plop it down at the end
val

But if you want something a little more concise, use this:

但如果你想要更简洁的东西,请使用:

if {table.uom_id} = 5 then
  {table.level} + ' feet'
else
  {table.level} + ' meters';