Error : A subscript must be between 1 and the size of the array?
Error : A subscript must be between 1 and the size of the array?
(OP)
I am stuck and in need of some desperate help.
Heres what I am trying to do:
I am new to Crystal Reports, I am a Lotus Developer who is using an SQL Driver to pull data from Notes into Crystal Reports so that I can create some fancy reports. The main problem is I have never worked with Crystal Reports, but from what I've seen it is a powerful tool and I'm sure I can split a field 3 times but I'm not sure how to do this.
I am using Crystal Reports 8. I have a field Category_Division.9, which has the following data (this is how it is displayed in Crystal Reports) :
ex. 01 Appliance\02 Needs Repair;02 Carpentry\05 Squeak in floor;10 Brick\01 Broken;21 Drywall\02 Wall Cracks; 01 Appliance\01 Install.
Heres What I would like it to look like:
ex. 01 Appliance
01 Install
02 Needs Repair
In other words the date will be categorized by everything before the "\"
Heres the code I have so far:
Local StringVar Array x;
Local StringVar Array TempArray;
Local Stringvar Temp;
Local Numbervar Remdash;
Local NumberVar loopI;
Local NumberVar loopJ;
Local StringVar CheckStr;
Local StringVar FormulaValue;
x:=Split ({@Size}, ";");
Temp:="";
for loopI:= 1 to ubound(x) do
(
loopJ:=1;
TempArray:=split(x[loopI],"\");
CheckStr:= TempArray[1];
if (instr(Temp,trim(TempArray[1])) < 1) then
(
Temp:= Temp & " | " & TempArray[1];
if trim(FormulaValue) <> "" then
(
if trim(right(FormulaValue,5)) ="" Then
(
FormulaValue:=left(FormulaValue,len(FormulaValue)-5);
);
);
FormulaValue:= FormulaValue & CheckStr & chr(13) & chr(10) & " ";
for loopJ:= 1 to ubound(x) do
(
TempArray:=split(x[loopJ],"\");
if (trim(CheckStr) = trim(TempArray[1])) then
(
Remdash = Instr(TempArray[2],"-");
if (Remdash > 0) then
(
TempArray[2] = Left(TempArray[2],Remdash-1);
);
FormulaValue:=FormulaValue & TempArray[2] & chr(10) & chr(13) ;
if (loopJ <> ubound(x)) Then
(
FormulaValue:=FormulaValue & " " ;
);
);
);
);
);
FormulaValue
I keep getting the following error:
A subscript must be between 1 and the size of the array
What am I doing wrong, does anyone have any other Ideas of how to get this to work?
Maybe a different code I can try that will give me the results that I want.
Is there also anyway to get away from the 254 character limit.
Thanks in advance for all your help
Heres what I am trying to do:
I am new to Crystal Reports, I am a Lotus Developer who is using an SQL Driver to pull data from Notes into Crystal Reports so that I can create some fancy reports. The main problem is I have never worked with Crystal Reports, but from what I've seen it is a powerful tool and I'm sure I can split a field 3 times but I'm not sure how to do this.
I am using Crystal Reports 8. I have a field Category_Division.9, which has the following data (this is how it is displayed in Crystal Reports) :
ex. 01 Appliance\02 Needs Repair;02 Carpentry\05 Squeak in floor;10 Brick\01 Broken;21 Drywall\02 Wall Cracks; 01 Appliance\01 Install.
Heres What I would like it to look like:
ex. 01 Appliance
01 Install
02 Needs Repair
In other words the date will be categorized by everything before the "\"
Heres the code I have so far:
Local StringVar Array x;
Local StringVar Array TempArray;
Local Stringvar Temp;
Local Numbervar Remdash;
Local NumberVar loopI;
Local NumberVar loopJ;
Local StringVar CheckStr;
Local StringVar FormulaValue;
x:=Split ({@Size}, ";");
Temp:="";
for loopI:= 1 to ubound(x) do
(
loopJ:=1;
TempArray:=split(x[loopI],"\");
CheckStr:= TempArray[1];
if (instr(Temp,trim(TempArray[1])) < 1) then
(
Temp:= Temp & " | " & TempArray[1];
if trim(FormulaValue) <> "" then
(
if trim(right(FormulaValue,5)) ="" Then
(
FormulaValue:=left(FormulaValue,len(FormulaValue)-5);
);
);
FormulaValue:= FormulaValue & CheckStr & chr(13) & chr(10) & " ";
for loopJ:= 1 to ubound(x) do
(
TempArray:=split(x[loopJ],"\");
if (trim(CheckStr) = trim(TempArray[1])) then
(
Remdash = Instr(TempArray[2],"-");
if (Remdash > 0) then
(
TempArray[2] = Left(TempArray[2],Remdash-1);
);
FormulaValue:=FormulaValue & TempArray[2] & chr(10) & chr(13) ;
if (loopJ <> ubound(x)) Then
(
FormulaValue:=FormulaValue & " " ;
);
);
);
);
);
FormulaValue
I keep getting the following error:
A subscript must be between 1 and the size of the array
What am I doing wrong, does anyone have any other Ideas of how to get this to work?
Maybe a different code I can try that will give me the results that I want.
Is there also anyway to get away from the 254 character limit.
Thanks in advance for all your help

Talk To Other Members
RE: Error : A subscript must be between 1 and the size of the array?
Funny, I just finished doing one of these (Not nearly as fancy as yours) and was getting the same error. What it ended up being was Nulls. I had to add a check for nulls and if any field was null I did a makearray.
Here is my code. The reason for my code is that the client was storing First Name and Middle initial in the first name field and Last Name and suffix in the LastName field.
Hope this helps you.
//begin code
StringVar Fname;
StringVar MName;
StringVar LName;
StringVar Suffix;
StringVar Array n;
redim preserve n[2];
n := if not isnull({Incident.First Name}) then Split ({Incident.First Name}," ",-1) else MakeArray(" "," ");
StringVar Array l;
redim preserve l[2];
l := if not isnull({Incident.Last Name}) then Split ({Incident.Last Name}," ",-1) else MakeArray(" "," ");
//end array for suffix in last name
FName := n[1] + " ";
MName := if ubound(n) = 2 then n[2] + " " else "";
LName := L[1] + ", ";
Suffix := if ubound(l) = 2 then l[2] else "";
Lname + Fname + MName + Suffix;
//end code
The reason that I used redim preserve on the field was that I knew the number of elements that were going to be contained in the array so I didn't have to loop through like you did.
Since I set the array to be 2 when I hit a null or an array that would be equal to 1 (less than the redim) it bombed with the An array must be between 1 and the size of the array.
Since you are setting the array size to the number of elements - I am assuming it is just the nulls.
Hope this helps,
ro
Rosemary Lieberman
rosemary@microflo.com, www.microflo.com
Microflo provides expert consulting on MagicTSD and Crystal Reports.
RE: Error : A subscript must be between 1 and the size of the array?