Crystal Reports公式中的错误

时间:2010-12-14 16:44:09

标签: reporting-services crystal-reports

我有一个全局变量,它在我的文档的Report Header部分的公式中声明。然后我尝试引用该变量以在for循环中使用它,我得到错误:

  

数字,货币金额,布尔值,   数据,时间,日期时间或字符串   期待在这里。

这里有什么问题,我该如何纠正?代码如下:

标题公式:

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;

4 个答案:

答案 0 :(得分: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是什么。

答案 1 :(得分: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")

答案 2 :(得分: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
"";

答案 3 :(得分:0)

我遇到了类似的问题-MS-Office中的字符与MS-DOS中的字符不同。将您的公式保存为严格的MS-DOS .txt文件,然后将其复制粘贴到CR公式编辑器中。

之前已经救了我