• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1407
  • Last Modified:

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

0
JD_Hynes
Asked:
JD_Hynes
  • 4
  • 4
  • 4
7 Solutions
 
mlmccCommented:
First, Crystal uses [ ] for arrays.

Where are you getting the error?

I have always used either
Shared NumberVar Array PhaseCode;
or
Shared NumberVar Array PhaseCode := [1,2,3,4,5';

to declare arrays.  I have never been successful with
Shared NumberVar Array PhaseCode[3];

mlmcc
0
 
JD_HynesAuthor Commented:
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?
0
 
mlmccCommented:
I haven't been able to do that.

MyArray[3] refers to the third element of the array not the size.

mlmcc
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
mlmccCommented:
I guess after first declarng it

NumberVar Array MyArray;
ReDim MyArray[SIze];

mlmcc
0
 
JD_HynesAuthor Commented:
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?
0
 
James0628Commented:
I assume the formula in the subreport is executed multiple times (Otherwise, you wouldn't really need an array, would you? :-)

 You've got the placement variable declared as local.  If ArraySize is 1 the first time through the formula, placement would be set to 1, but on subsequent passes through the formula, placement would default to 0, and that would give you the error you mentioned.

 Is the subreport run more than once by the main report?  If so, is the subreport supposed to just keep adding values to the end of the array, or should the array be started fresh by each new subreport?

 If the subreport is only run once, placement can be Global or Shared.

 If the subreport should keep adding values to the end every time it's run, placement needs to be Shared.  If the subreport should start the array fresh each time it's run, Placement can be Global, or it can be Shared, but reset to 0 at the start of the subreport.


 Other odds and ends:

 Is the formula with the array declaration in the main report in a section _before_ the section with the subreport in it?  Just checking.

 Do you really need to start the array size at 1?  I would let it start at the default size (whatever that is) and increase it as necessary.  In the formula in the subreport, you could have something like:

// Initialize placement
if placement = 0 then
  placement := 1;

if UBound (PhaseCode) < placement + 1 then
  //resize of the array that preserves the contents
  ReDim Preserve PhaseCode [ placement + 1 ];


 However, if you're expecting more than just a few values to be put in the array, I would go a step further by increasing the size of the array in larger increments.  The theory is that using ReDim over and over to add 1 more element at a time to the array is less efficient than using it less often to add more elements at a time.  Just replace the 1 in the ReDim statement with a larger increment (eg. 10 or 100).  The if would still use "placement + 1".  Just change the ReDim.


 Also, the formula that you posted to output the values in the array will only output the last value in the array.  The for loop will dump each value into MyOutput and all that you'll get at the end if the last value put in that variable.  If you want to see all of the values, you'll have to do something else.

 James
0
 
James0628Commented:
The end of the next to last sentence should read:

 ... and all that you'll get at the end is the last value put in that variable.

 I had "if the last value".

 James
0
 
mlmccCommented:
what is th ecode trying to do?

mlmcc
0
 
JD_HynesAuthor Commented:
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.

0
 
James0628Commented:
Of course CR doesn't support multi-dimensional arrays, so if you want to save more than one set of values, you'll probably want to use a separate array for each set.

 James
0
 
JD_HynesAuthor Commented:
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.
0
 
James0628Commented:
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now