8

バックグラウンド

  • レポートの詳細行で見栄えの良い検証を行おうとしています。
  • Assertステートメントという名前の数式がいくつかあります。これらの数式は、テストに失敗した場合はfalseを返し、合格した場合はtrueを返します。

ゴール

  • 「ルール違反」を格納する配列を作成し、行の最後の「BrokenRules」という見出しの下のフィールドに表示したいと思います。

私がこれまでにしたこと

  • 配列を作成し、レポートヘッダーで空の文字列配列として初期化しました
  • 各ルールの評価を行い、配列をインクリメントし、壊れたルール番号を追加する式を作成しました(これはルールごとに繰り返されるコードであり、特別なことは何もありません)。これは、詳細表示の上の抑制された詳細セクションに追加されます。
  • ルールが壊れた配列の要素を結合した式を作成しました。これは、詳細フィールドと一緒に表示される数式です。
  • ルールの壊れた配列を空に設定する式を作成しました。これは、詳細が表示された後、抑制された詳細セクションに入ります。

問題

  • Crystalは、私が見つけることができる「endif」ステートメントを許可していないようです。
  • そのため、1つの数式内で複数のIfステートメントを評価することはできず、1つのIfステートメントしか評価できないようです。
  • これは、ルールごとに1つずつ、複数のifを実行できないことを意味します。

サンプルコード

配列の作成(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;
"";

配列をインクリメントして値を追加する最初の3つのルール評価のサンプル(これは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

何か案は?

  • CrystalReportsにIf/then / end if機能はありますか?
  • そうでない場合は、Crystal Reportsにこの種の回避策がありますか?それぞれに複数の数式を作成し、それらが次々に配置されていることを確認する必要がありますか?

助けてくれてありがとう!

4

1 に答える 1

12

コードでこれを行う最も簡単な方法は、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 がブロックを解釈する方法を示すインデントを追加しました。

于 2012-04-19T01:54:52.423 に答える