SeanKilleen
SeanKilleen

Reputation: 8977

Crystal Report: How to evaluate multiple IF statements in one formula?

Background

Goal

What I've done so far

Problem

Sample Code

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

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

Any Ideas?

Thanks in advance for any help!

Upvotes: 8

Views: 22201

Answers (1)

paulmelnikow
paulmelnikow

Reputation: 17208

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

I added indentation indicating how Crystal interprets the blocks.

Upvotes: 12

Related Questions