2010-12-14 34 views
2

私はドキュメントのレポートヘッダーセクションの式で宣言されたグローバル変数を持っています。その変数をforループで使用するように参照しようとすると、エラーが発生します。Crystal Reports式のエラー

A number, currency amount, boolean, data, time, date-time, or string is expected here.

ここで何が間違っていますか?コードは次のとおりです。

ヘッダー式:

Global StringVar Array items; 
redim items [1]; 

Global StringVar Array jobs; 
redim jobs [1]; 

Global StringVar Array POs; 
redim POs [1]; 

Global StringVar Array Qty; 
redim Qty [1]; 

Global NumberVar numRecordsPrinted; 
numRecordsPrinted := 0; 

"" 

詳細式:

Local NumberVar occurances; 
    Local StringVar poTOuse; 
    Local NumberVar i; 

    if {%Line_PO_Test} <> '' 
    and {PackingSlipHeader.CompanyCode} <> '10063' 
    and {PackingSlipHeader.CompanyCode} <> '10017' 
    then 
     //Count the number of occurances 
     For i := 0 To numRecordsPrinted Do  //Error on numRecordsPrinted 
     (
      if items[i] = {PS_DETAIL_FOR_PRINT.DTSItemNumber} 
       AND jobs[i] = {PS_DETAIL_FOR_PRINT.JobNumber} 
       And Qty[i] = {PS_DETAIL_FOR_PRINT.Quantity_Shipped} 
       THEN 
        occurances := occurances + 1 
     ) 

     //Use the # of occurances to get the right PO number 
Select occurances 
     case 0: poTOuse := {@LinePOnum} 
     case 1: poTOuse := {@Line_PO_3} 
     case 2: poTOuse := {@Line_PO_2} 

     default: poTOuse := ""; 


     //Save data into the array and increment for next time 
     numRecordsPrinted := numRecordsPrinted + 1 
     items[numRecordsPrinted] := {PS_DETAIL_FOR_PRINT.DTSItemNumber} 
     jobs[numRecordsPrinted] := {PS_DETAIL_FOR_PRINT.JobNumber} 
     Qty[numRecordsPrinted] := {PS_DETAIL_FOR_PRINT.Quantity_Shipped} 

    //Print to the report 
    'PO#: ' + poTOuse; 

答えて

1

Crystal Reportsの構文では、変数を使用するたびに変数を宣言する必要があります。ヘッダー式と詳細式の両方で変数を宣言しなければならないことに気づいていませんでした。他の小さな構文エラーもありましたが、それが大きな問題でした。

ほとんどの言語で変数を複数回宣言すると、プログラムはコンパイルされず、実行されないため、私はこれを可能性とは考えませんでした。

ヘッダーセクション

BeforeReadingRecords; 

Global StringVar Array items; 

Global StringVar Array jobs; 

Global StringVar Array POs; 

Global NumberVar Array Qty; 

Global NumberVar numRecordsPrinted; 

"" 

詳細セクション

WhileReadingRecords; 
Global StringVar Array items; 

Global StringVar Array jobs; 

Global StringVar Array POs; 

Global NumberVar Array Qty; 

Global NumberVar numRecordsPrinted; 
Global NumberVar occurances; 
occurances := 0; 

Global StringVar poTOuse; 
Global NumberVar i; 

ReDim Preserve items[CDbl(Ubound(items) + 1)]; 
ReDim Preserve jobs[CDbl(Ubound(jobs) + 1)]; 
ReDim Preserve POs[CDbl(Ubound(POs) + 1)]; 
ReDim Preserve Qty[CDbl(Ubound(Qty) + 1)]; 

if {%Line_PO_Test} <> "" 
and {PackingSlipHeader.CompanyCode} <> "10063" 
and {PackingSlipHeader.CompanyCode} <> "10017" 
then 
    //Count the number of occurances 
    For i := 1 To (numRecordsPrinted + 1) Do 
    (
     if items[i] = {PS_DETAIL_FOR_PRINT.DTSItemNumber} 
      AND jobs[i] = {PS_DETAIL_FOR_PRINT.JobNumber} 
      And Qty[i] = {PS_DETAIL_FOR_PRINT.Quantity_Shipped} 
      THEN 
       occurances := occurances + 1 
    ); 

    //Use the # of occurances to get the right PO number 
    Select occurances 
     case 0: poTOuse := {%Line_PO_Test} 
     case 1: poTOuse := {%Line_PO_3} 
     case 2: poTOuse := {%Line_PO_2} 

     default: poTOuse := ""; 

    //Save data into the array and increment for next time 
    numRecordsPrinted := numRecordsPrinted + 1; 
    items[numRecordsPrinted] := {PS_DETAIL_FOR_PRINT.DTSItemNumber}; 
    jobs[numRecordsPrinted] := {PS_DETAIL_FOR_PRINT.JobNumber}; 
    Qty[numRecordsPrinted] := {PS_DETAIL_FOR_PRINT.Quantity_Shipped}; 

//Print to the report 
if poTOuse <> "" THEN 
'PO#: ' + poTOuse 
ELSE 
""; 
1

確かにこのビット:

Select occurances 
     case 0: poTOuse = LinePOnum 
     case 1: poTOuse = Line_PO_3 
     case 2: poTOuse = Line_PO_2 

     default: poTOuse = ""; 

Select occurances 
     case 0: poTOuse := LinePOnum 
     case 1: poTOuse := Line_PO_3 
     case 2: poTOuse := Line_PO_2 

     default: poTOuse := ""; 
01でなければなりませんが

LinePOnum、Line_PO_3、およびLine_PO_2はどのようなものかはっきりしませんが。

+0

はい、あなたが正しいように見えます。これらはCrystal Reportの他の数式ですが、私はそれらを適切に参照しませんでした。私はこの部分を修正し、質問を編集します。エラーコードに関するアイデアはありますか? – MAW74656

1

このようにコードの次のセクションをコメントアウトすると、エラーが表示されますか?

For i := 0 To numRecordsPrinted Do  //Error on numRecordsPrinted 
     (
//   if items[i] = {PS_DETAIL_FOR_PRINT.DTSItemNumber} 
//    AND jobs[i] = {PS_DETAIL_FOR_PRINT.JobNumber} 
//    And Qty[i] = {PS_DETAIL_FOR_PRINT.Quantity_Shipped} 
//    THEN 
        occurances := occurances + 1 
     ) 

「はい」の場合は、occurances := occurances + 1をコメントアウトするとエラーが表示されますか?

配列はStringVarsなので、あなたはこのようなcstrを使用してデータベースフィールドをラップする必要があるかもしれません:

(
     if items[i] = cstr({PS_DETAIL_FOR_PRINT.DTSItemNumber}) 
      AND jobs[i] = cstr({PS_DETAIL_FOR_PRINT.JobNumber}) 
      And Qty[i] = cstr({PS_DETAIL_FOR_PRINT.Quantity_Shipped}) 
      THEN 
       occurances := occurances + 1 
    ) 

あなたはQuantity_Shippedための末尾の小数点以下を削除したい場合は、あなたの代わりにcstr({PS_DETAIL_FOR_PRINT.Quantity_Shipped}, "0")を使用することができます。

+0

これらのどれも主な問題ではありませんでしたが、あなたが見て調査する時間がかかっていたので、あなたは恩恵に値するでしょう。ご協力いただきありがとうございます。 – MAW74656