Link to home
Start Free TrialLog in
Avatar of JD_Hynes
JD_HynesFlag for United States of America

asked on

Crystal Syntax Array Size not declaring properly.

So I have a subreport that is taking in data from two different fields into an array.  I have declared the array size and the Array in the Main report. When I run the Report it tells me that the Array has to be 1 or larger.


//The array Declaration in the Main report
WhilePrintingRecords;
Shared NumberVar ArraySize:=1;
Shared NumberVar Array PhaseCode(ArraySize);
 
//The Array Implementation in the subreport
 
Shared NumberVar ArraySize;
Shared NumberVar Array PhaseCode;
local numbervar placement;
 
 
if(ArraySize < 2 )
 then (ArraySize := 2;
   placement := 1);
//resize of the array that preserves the contents
ReDim Preserve PhaseCode[ArraySize];
 
 
 
//null check and adds to the array and converts the type to a number from a string
if ((isNull({VN_SUBCONTRACT_MC.Default_Phase_Code}) AND isNull({PO_PURCHASE_ORDER_DETAIL_MC.Phase_Code})) = false)
then
    (PhaseCode[placement] := ToNumber({PO_PURCHASE_ORDER_DETAIL_MC.Phase_Code});
    placement := placement + 1;
    PhaseCode[placement] := ToNUmber({VN_SUBCONTRACT_MC.Default_Phase_Code});
    placement := placement + 1;
    ArraySize := ArraySize + 2;)
else If isNull({PO_PURCHASE_ORDER_DETAIL_MC.Phase_Code}) then  
    (PhaseCode[placement] := ToNUmber({VN_SUBCONTRACT_MC.Default_Phase_Code});
    placement := placement + 1;
    ArraySize := ArraySize + 1;)
else if isNull({VN_SUBCONTRACT_MC.Default_Phase_Code}) then 
    (PhaseCode[placement] := ToNumber({PO_PURCHASE_ORDER_DETAIL_MC.Phase_Code});
    placement := placement + 1;
    ArraySize := ArraySize + 1;)
else if ((isNull({VN_SUBCONTRACT_MC.Default_Phase_Code}) AND isNull({PO_PURCHASE_ORDER_DETAIL_MC.Phase_Code})) = true)
then
    ArraySize := ArraySize; 
 
//Printing out the array in the Details section of the report. 
 
WhilePrintingRecords;
Shared NumberVar Array PhaseCode;
Shared NumberVar ArraySize;
Local NumberVar i;
Local NumberVar MyOutput;
 
For i:=1 to UBound(PhaseCode) do
    MyOutput :=PhaseCode[i];
 
MyOutput;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JD_Hynes

ASKER

Yah, I noticed that after I posted... I am recieving the error in Spectrum, another program we use to run the reports out of.  "A subscript must be between 1 and the size of the array." is the error text.  

Am I wrong to assume that I can declare the size of the array and not input values doing it the way I posted?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For some reason it won't pass values for the size down to the subreport.  It seems to be calling the error from the subreport function.  it doesn't know what the value is for arraysize.  Any thoughts?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The code is trying to combine two fields in tables that really have no way to link.  I tried doing a temp table, but spectrum would not allow me to create a "new table" or a virtual table to shove everything together.  So my solution was do create an array that would take in two tables and then sort the values based off of the "Phase" in the end this is going to be a multi-dimensional array.  so the array would include PhaseArray[Phase, billed, ect, ect]  and sort the values off of the phase in numerical order...But at the moment I am trying to even get it to work.

I am going to try and make the changes that James suggested.  Yes the report runs more then once, and I think at that point I will increase the array size in 10 sized increments.  I believe the print value should probably print out inside the subreport.  each of the subreports are divided by the jobcode value.  so we are printing out all the phase codes inside that jobcode.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I changed direction now because my datasets are too large for arrays.  Even with daisy-chaining the arrays within multiple forumlas it would still go out of range.  

Thanks for your help guys.  I will probably be around with more questions.
Avatar of James0628
James0628

Yeah, arrays can be very useful, but they have their limits.  If you're dealing with a lot of data, then even if you could use arrays, they're probably not going to be a very good solution.

 I'm not too sure what you're trying to do, but if you're trying to get a report to show related data from different tables and can't just link them, maybe you could use one or more subreports to show the data from different tables.  Of course there must be some way to connect the information, or there's not going to be any way to pull the correct data, and if there's a connection, are you sure that the tables can't be linked?

 James