Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A subscript must be between 1 and the size of the array.

Status
Not open for further replies.

charithb

IS-IT--Management
Feb 20, 2013
5
0
0
CA
Hello forum,

I have the below formula embedded in my report...
//
WhilePrintingRecords;
StringVar Array parts;


if parts[1] = "" then parts[1] := {@addParentParts}
else if not({@addParentParts} in parts) then
(
redim preserve parts[Ubound(parts)+1];
parts[UBound(parts) + 1] := {@addParentParts};
)
//
but when i run the report, i get the below error message...

---------------------------
Crystal Reports
---------------------------
A subscript must be between 1 and the size of the array.
---------------------------
OK
---------------------------

Can someone please advice me how to resolve this error? what am i doing wrong here?

Regards,
Charith
 
Crystal does not allow you to build arrays on the fly. You must define the array at some point before you want to use it.

Formula like this must be used with the max number of elemnets as required

@Reset
WhilePrintingRecords;
StringVar Array parts:=["", "", "", "", "", ""..... with as many elements as required]

Ian

 
Thank you for your reply...

But i did define and initialize the array as a shared variable (in a formula), and placed it in the report header section.

//
Shared StringVar Array parts := [""];
Shared numberVar x := 1;
//

Does this changes anything? or do i have to follow your instructions regardless.

Regards,
C
 
C,

I am not as familiar with Arrays as Ian undoubtedly is, but I would suggest that your definition created an array with one element. (assuming I understood Ian's post correctly).

Code:
Shared StringVar Array parts := [""];
The ""'s within the [] represent an element, as you have defined only 1, I would assume this to be the root of the error.

A quick test would be to modifuy your existing formula to the following:
Code:
Shared StringVar Array parts := ["",""];
This will create an Array of 2 elements and in theory remove the error. You will need to then define as per Ian's post. with the proper number of elements defined.

Again, all of this is based on my interpretation of Ian's posting. [smile] Ian -- please correct me if I am out in Left Field looking the fool.

Cheers!

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
Thank you so much MCuthill. I will try the above.

You guys are the best! really appreciate all the help and assistance.

Regards,
C
 
I generally build an array of the size I need. However, in theory you can start with an array of one element and the use Redim to resize. But I have not used that so can not advise.

Need to make sure {@addParentParts} is returning a value as expected.
Place this on report ans suppress Array formula to test values incrementing as expected.

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top