创建数组(一个名为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的公式中):
//@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
提前感谢您的帮助!
答案 0 :(得分: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 ""
);
我添加了缩进,表明Crystal如何解释块。