Crystal Report:如何在一个公式中评估多个 IF 语句? [英] Crystal Report: How to evaluate multiple IF statements in one formula?

查看:19
本文介绍了Crystal Report:如何在一个公式中评估多个 IF 语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我正在尝试对报告的详细信息行进行一些漂亮的验证.
  • 我有几个名为 Assert 语句的公式,如果测试失败则返回 false,如果测试通过则返回 true.
  • 我想创建一个存储违反规则"的数组,然后将它们显示在行尾的字段中,标题为Broken Rules"
  • 创建了一个数组并将其初始化为报表头中的空字符串数组
  • 创建了一个公式来评估每个规则,增加数组,并添加损坏的规则编号(这是每个规则的重复代码,没什么花哨的).这会添加到我的详细信息显示上方的隐藏详细信息部分.
  • 创建了一个公式,它是规则破坏数组中元素的连接.这是与我的详细信息字段一起显示的公式.
  • 创建了一个公式以将规则损坏的数组设置为空.这会在我的详细信息显示后显示在隐藏的详细信息部分中.
  • Crystal 似乎不允许使用我能找到的end if"语句.
  • 因此,我似乎只能评估一个 If 语句,而不是单个公式中的倍数.
  • 这意味着我不能执行多个 if,每个规则一个.

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

Creation of the Array (a formula called 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;
"";

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

Sample of first three rule assessments that increment arrays and add values (this is in a formula called 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

有什么想法吗?

  • Crystal Reports 中是否有 If/then/end if 功能?
  • 如果没有,Crystal Reports 中是否有解决此类问题的方法?我是否需要为每个公式创建多个公式并确保将它们放在另一个之后或类似的地方?
  • 提前感谢您的帮助!

    推荐答案

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

    The simplest way to do this with the code you have is wrapping the if blocks in parentheses and separating them with semicolons:

    //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 ""
    );
    

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

    I added indentation indicating how Crystal interprets the blocks.

    这篇关于Crystal Report:如何在一个公式中评估多个 IF 语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆