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

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

问题描述


  • 我正试图在报告的详细信息行上做一些漂亮的验证。

  • 我有几个名为Assert语句的公式,如果测试失败则返回false,如果通过则返回true。


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


  • 创建一个数组并在报告头中将其初始化为空字符串数组

  • 创建一个公式来评估每个规则,增加数组,并添加破碎的规则编号(这是每个规则的重复代码,没有什么花哨的)。这将添加到我的详细信息显示上方的抑制详细信息部分。

  • 创建一个公式,它是规则损坏数组中元素的连接。这是一个与我的详细信息字段一起显示的公式。

  • 创建一个公式,将规则已损坏的数组设置为空。在我的详细信息显示后,这会显示在详细信息部分。

  • Created an Array and Initialized it as an empty string array in the report header
  • Created a formula to do evaluation of each rule, increment the array, and add the broken rule number (this is repeated code for each rule, nothing fancy). This gets added into a suppressed details section above my details display.
  • Created a formula that is a join of the elements in the rules broken array. This is a formula that is displayed along with my detail fields.
  • Created a formula to set the rules broken array to empty. This goes in a suppressed details section after my details display.

  • Crystal似乎不允许我找到end if语句。

  • 因此,似乎我只能评估一个If语句和不是单个公式中的倍数。

  • 这意味着我不能做多个ifs,每个规则一个。

创建数组(一个名为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?我是否需要为每个公式创建多个公式,并确保它们放在另一个或类似之后?

  • 谢谢提前获取任何帮助!

    Thanks in advance for any help!

    推荐答案

    使用您的代码执行此操作的最简单方法是将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天全站免登陆