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
Thanks in advance for any help!
To add the formula field, go to the Field Explorer panel. Click on Formula Fields to select it. Right click on Formula Fields, then select New.
IIF and IsNull are functions in Crystal Reports that are used in formulas to test fields for blanks, empty strings, missing values and NULL, then return some valid output. This is especially helpful when preparing a report, since these values can cause blank lines to be printed.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With