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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Message. a subscript must be between 1 and the size of the array

Status
Not open for further replies.

JAM1011

Programmer
Feb 13, 2010
6
IE
Hey all,

I am very new to crystal reports and really need to solve problem as soon as possible.
I am trying to pull value in from an access database . It is a parts field which is require for a invoice.
There a string with this format PartName-QTY-Cost + PartName-QTY-Cost + etc
I ould love to if possible to split EACH part into 3 different text boxes so in the above example there would be six text boxes. But if this proves to be too difficult I would be happy if i could get each part details on different lines if the same text box. I really need to get this sorted. I have tried using the split function but I can't get it to work correctly .

Please any help at all is will come .

Here is the code I am using


Global StringVar Array PartsList;
Global StringVar Array PartNameList;
Global StringVar Array QtyList;
Global StringVar Array CostList;
Local StringVar Array PartLine;
Local NumberVar index;
PartsList := Split({tblMachineHistory.Parts},'+');
For index := 1 to UBound(PartsList) do
(
PartLine := Split(PartsList[index],'-');
PartNameList[index] := PartLine [1];
QtyList[index] := PartLine [2];
CostList[index] := PartLine [3];
);


Thanks

James
 
Try:

StringVar Array PartsList;
StringVar Array PartNameList;
StringVar Array QtyList;
StringVar Array CostList;
Local StringVar Array PartLine;
Local NumberVar i;
PartsList := Split({tblMachineHistory.Parts},'+');
numbervar j := ubound(PartsList);
numbervar k;
For i := 1 to j do
(
k := k + 1;
if k <= j * 3 then(
Redim Preserve PartLine[j];
PartLine := Split(PartsList,'-');
Redim Preserve PartNameList[j];
PartNameList[k] := PartLine[1];
Redim Preserve QtyList[j];
QtyList[k] := PartLine [2];
Redim Preserve CostList[j];
CostList[k] := PartLine [3];
));

-LB
 
Thanks for the fast reply. I use the code you suggested.

But this an error message pops up

A subscript must be between 1 and the size of the array.
Error in file and list the file location
Error in formula <parts>
'StringVar Array PartList;

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

Also the value of True in the unbound text-box.
Any ideas thanks for input I really appreciate .

Thanks
James
 
I thought it was called PartsList, not PartList--make sure the variable has the same name in all places. Yes, the formula returns true. You can then reference whichever element you want by adding a last line, e.g.,

CostList[3]

This formula also assumes that are are always three elements in the a segment of the field--item-qty-price. If they can be null, the formula needs to be changed. I did test this, and it worked for me. If it doesn't work for you, please post the entire new formula here.

-LB
 
Ok still getting the same error but PartsList instead of PartList. Also it don't give the location but the following Users/James/AppData/Temp/CrystalReport3........

I know its something stupid I am doing wrong. The code I am using is below Also i am using Crystal Reports with VS Pro 2008 if that make any difference. There is a maximum of 15 parts and their details. Here is a sample String from the access database

"Airfliter-3-12+Oil- 1-12+FuelFilter-2-3"

Code/////
StringVar Array PartsList;
StringVar Array PartNameList;
StringVar Array QtyList;
StringVar Array CostList;
Local StringVar Array PartLine;
Local NumberVar i;
PartsList := Split({tblMachineHistory.Parts},'+');
numbervar j := ubound(PartsList);
numbervar k;
For i := 1 to j do
(
k := k + 1;
if k <= j * 3 then(
Redim Preserve PartLine[j];
PartLine := Split(PartsList,'-');
Redim Preserve PartNameList[j];
PartNameList[k] := PartLine[1];
Redim Preserve QtyList[j];
QtyList[k] := PartLine [2];
Redim Preserve CostList[j];
CostList[k] := PartLine [3];
CostList[3]

));



Thanks
JAMES
 
Sorry, I should have had k := 0, as in:

StringVar Array PartsList;
StringVar Array PartNameList;
StringVar Array QtyList;
StringVar Array CostList;
Local StringVar Array PartLine;
Local NumberVar i;
PartsList := Split({tblMachineHistory.Parts},'+');
numbervar j := ubound(PartsList);
numbervar k := 0;
For i := 1 to j do
(
k := k + 1;
if k <= j * 3 then(
Redim Preserve PartLine[j];
PartLine := Split(PartsList,'-');
Redim Preserve PartNameList[j];
PartNameList[k] := PartLine[1];
Redim Preserve QtyList[j];
QtyList[k] := PartLine [2];
Redim Preserve CostList[j];
CostList[k] := PartLine [3];
//[crRed]CostList[3] //remove this [/crRed]
));

I would then do separate formulas like this:

//{@CostList3}:
evaluateafter({@yourformula});
whileprintingrecords;
stringvar array CostList;
if ubound(CostList) >= 3 then
CostList[3];

-LB
 
I still get the error I examplain above but it does work kinda. Do you have any idea how to loop through the array value and then to the text-box. So for example
Airfliter-3-12+Oil- 1-12+FuelFilter-2-3+Plug-4-6

Airfliter next in text-box
Oil next in text-box
FuelFilter next in text-box
Plug Etc


Also do you have any idea what might be causing the error explain above.

Can I use a try catch or some thing?

Thanks again you are being very patient and helpful. This help is really getting my out of a fix.


Thanks
James
 
If that's all you want to do, then I think you should change your approach and create a formula:

replace({tblMachineHistory.Parts},"+",chr(13))

Format the formula to "Can grow".

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top