Crystal Report:如何在一个公式中评估多个IF语句?

Sea*_*een 7 arrays if-statement formula crystal-reports crystal-reports-2008

背景

  • 我正试图在我的报告的详细信息行上做一些漂亮的验证.
  • 我有几个名为Assert语句的公式,如果测试失败则返回false,如果它们通过则返回true.

目标

  • 我想创建一个存储"规则违规"的数组,然后将它们显示在行末的字段中,名为"Broken Rules"的标题下

到目前为止我做了什么

  • 创建一个Array并将其初始化为报表头中的空字符串数组
  • 创建了一个公式来评估每个规则,增加数组,并添加破碎的规则编号(这是每个规则的重复代码,没有什么花哨的).这将添加到我的详细信息显示上方的抑制详细信息部分.
  • 创建了一个公式,它是规则损坏数组中元素的连接.这是一个与我的详细信息字段一起显示的公式.
  • 创建了一个公式,将规则broken数组设置为空.在显示详细信息后,这会显示在详细信息部分中.

问题

  • Crystal似乎不允许我能找到的"end if"语句.
  • 因此,似乎我只能评估一个If语句而不是单个公式中的倍数.
  • 这意味着我不能做多个ifs,每个规则一个.

示例代码

创建数组(一个名为Init_StringVar_Array_RulesBroken的公式):

//@Init
//This goes into the report header
WhilePrintingRecords;

//initializes the array of broken rules which we'll add to during details
StringVar Array RulesBroken;
"";
Run Code Online (Sandbox Code Playgroud)

前三个规则评估的示例,用于递增数组和添加值(这在名为Increment_StringVar_Array_RulesBroken的公式中):

//@Increment
//Goes before the details section is displayed

//accesses the shared variable
WhilePrintingRecords;
StringVar Array RulesBroken;

//separate if statement for each assert statement

//01
if not {@Assert_01_IfCrewIsConstructionCrew_CBFlagShouldBeYesOrDirect} then
Redim Preserve RulesBroken[UBound(RulesBroken) + 1]; //extends the array to be able to hold one more item than it does currently
RulesBroken[UBound(RulesBroken)] := "01"; //adds the new string into the array

//02
if not {@Assert_02_IfCrewIsConstructionCrew_AndCBFlagIsDirect_WONumberShouldStartWithC} then
Redim Preserve RulesBroken[UBound(RulesBroken) + 1]; //extends the array to be able to hold one more item than it does currently
RulesBroken[UBound(RulesBroken)] := "02"; //adds the new string into the array

//03
if not {@Assert_03_IfCrewIsDesign_AndCBFlagIsDirect_WONumberShouldStartWithD} then
Redim Preserve RulesBroken[UBound(RulesBroken) + 1]; //extends the array to be able to hold one more item than it does currently
RulesBroken[UBound(RulesBroken)] := "03"; //adds the new string into the array
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

  • Crystal Reports中是否有if/then/end if功能?
  • 如果没有,Crystal Reports中是否有针对此类事情的解决方法?我是否需要为每个公式创建多个公式,并确保它们放在另一个或类似的东西之后?

在此先感谢您的帮助!

pau*_*kow 10

使用您的代码执行此操作的最简单方法是将if块包装在括号中并用分号分隔它们:

//01
(
    if not {@Assert_01_IfCrewIsConstructionCrew_CBFlagShouldBeYesOrDirect} then
        Redim Preserve RulesBroken[UBound(RulesBroken) + 1];
        RulesBroken[UBound(RulesBroken)] := "01"
    else ""
);

//02
(
    if not {@Assert_02_IfCrewIsConstructionCrew_AndCBFlagIsDirect_WONumberShouldStartWithC} then
        Redim Preserve RulesBroken[UBound(RulesBroken) + 1];
        RulesBroken[UBound(RulesBroken)] := "02"
    else ""
);

//03
(
    if not {@Assert_03_IfCrewIsDesign_AndCBFlagIsDirect_WONumberShouldStartWithD} then
        Redim Preserve RulesBroken[UBound(RulesBroken) + 1];
        RulesBroken[UBound(RulesBroken)] := "03"
    else ""
);
Run Code Online (Sandbox Code Playgroud)

我添加了缩进,指示Crystal如何解释块.

  • `else""`可能会奏效.那很奇怪; 我不认为其他是必需的. (2认同)