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 SkipVought 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.

DennisY

Technical User
Oct 5, 2022
5
0
0
US
I am new to this in depth of crystal reports. I inherited this report I am not the original author.

Here is the formula I am using

//shared stringvar GSval := GSval & Sum ({@grossSales}, {SalesClass.RecDate}, "quarterly") & "^"
Local numbervar x := 1;
Local numbervar y := 0;
Local stringvar tempStr := "";
shared stringvar showval;
whileprintingrecords;
//shared stringvar showval := showval + totext({@diffPercent}) + "^";
Select (GroupName ({SalesClass.RecDate}, "quarterly"))
Case "1/" & toText(Year(Currentdate)-3,0,""):
y := 1
Case "4/" & toText(Year(Currentdate)-3,0,""):
y := 2
Case "7/" & toText(Year(Currentdate)-3,0,""):
y := 3
Case "10/" & toText(Year(Currentdate)-3,0,""):
y := 4
Case "1/" & toText(Year(Currentdate)-2,0,""):
y := 5
Case "4/" & toText(Year(Currentdate)-2,0,""):
y := 6
Case "7/" & toText(Year(Currentdate)-2,0,""):
y := 7
Case "10/" & toText(Year(Currentdate)-2,0,""):
y := 8
Case "1/" & toText(Year(Currentdate)-1,0,""):
y := 9
Case "4/" & toText(Year(Currentdate)-1,0,""):
y := 10
Case "7/" & toText(Year(Currentdate)-1,0,""):
y := 11
Case "10/" & toText(Year(Currentdate)-1,0,""):
y := 12
Case "1/" & toText(Year(Currentdate),0,""):
y := 13
Case "4/" & toText(Year(Currentdate),0,""):
y := 14
Case "7/" & toText(Year(Currentdate),0,""):
y := 15
Case "10/" & toText(Year(Currentdate),0,""):
y := 16;
for x := 1 to 16 Do(
Local stringvar z := "";
z := split(showval,"^")[x];
if x = y then
tempStr := tempStr + totext((Sum ({SalesClass.SalePrc}, {SalesClass.RecDate}, "quarterly")+Sum ({SalesClass.DiscAmnt}, {SalesClass.RecDate}, "quarterly")),0,"") + "^"
else
tempStr := tempStr + z + "^"
);
shared stringvar showval := Left(tempStr, Len(tempStr)-1)


The error is happing in this section I believe

z := split(showval,"^")[x];

Any suggestion on how to fix this error is appreciated.
 
What is the text of the error you are receiving?

Also, what are the contents of the formula {@diffPercent}?
 
Try changing the line:

Code:
for x := 1 to 16 Do(

To:

Code:
for x := 1 to y Do(

Hope this helps.

Cheers,
Pete.
 
@fisheromacs The text of the error is A subscript must be between 1 and the size of the array

and the formula editor pops up with z := split(showval,"^")[x]; highlighted so I am assuming it is having an issue doing the split.

Not sure what you mean by contents of the formula? This report is generating the Overhead as a percentage of net sales by Quarter
 
@pmax9999 I tried that and the same error pops up but a lot faster
 
Is there a reason the line setting the variable showval has been commented out?

 
It is pretty difficult to troubleshoot a formula like this without understanding the underlying data and what it is attempting to achieve.

If you can upload the report with saved data I'd be happy to take a look.
 
@pmax9999 I do not know, like I said I am new and I inherited this. It was already commented out when I got this.

If I uncomment it tells me the field name @diffPercent is not known. So maybe old code from the last guy when he was making this report and it was not needed

I do not have a field/file @diffPercent

I was wondering if it could be a blank or Null field in the data that showval is trying to split? Is there a way to stick a check in for that. Just a guy that knows little about this thinking out loud
 
If you can upload the report with saved data I'd be happy to take a look.
 
you can do a null/value test before the Split.
something like
Code:
Local stringvar z := "";
IF isnull(showval) = TRUE then z := "NULL" ELSE 
IF TRIM(showval) = "" then z := "BLANK"  ELSE  
z := split(showval,"^")[x];

but from what you have shared so far, i don't think showval is getting any value except the "" assigned to it, as a result there is nothing to split.
As pmax has said, it is difficult to troubleshoot a complex report issue without data and a good understanding of what the desired outcome should be.
 
Thanks for the help. Sorry to waste anyone's time. I found a bigger issue with the report which is most likely causing this. a whole section of detail is missing so this is basically an unfinished report.

But I did learn some new things which is always a good thing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top