I have a global variable which was declared in a formula in the Report Header section of my document. I then try to reference that variable to use it in a for loop, and I get the error:
A number, currency amount, boolean,
data, time, date-time, or string is
expected here.
What is wrong here and how can I correct? Code follows:
Header Formula:
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;
""
Detail Formula:
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;
In crystal reports syntax, the variables have to be declared each time you use them. I wasn’t aware that I have to declare the variables both in the header formula, and the detail formula. I made some other small syntax errors, but that was the main problem.
I didn’t even consider this as a possibility because in most languages, declaring a variable more than once will cause the program to not even compile, let alone run.
Header Section
Detail Section