2010-12-14 110 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

在晶体报告语法中,变量必须在每次使用时声明。我不知道我必须在标题公式和详细公式中声明变量。我犯了一些小的语法错误,但那是主要问题。

我甚至没有考虑过这种可能性,因为在大多数语言中,多次声明一个变量会导致程序甚至无法编译,更不用说运行了。

报头部分

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

虽然目前尚不清楚LinePOnum,Line_PO_3和Line_PO_2是什么。

+0

是的,看起来像你的正确。这些是其他Crystal Report公式,但我没有正确引用它们。我会纠正这部分并编辑问题。关于错误代码的任何想法? – MAW74656 2010-12-14 17:47:32

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 2010-12-20 17:33:24