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

Error : A subscript must be between 1 and the size of the array?

Status
Not open for further replies.

NotesGuy1

MIS
Jun 25, 2002
2
US
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 & &quot; | &quot; & TempArray[1];
if trim(FormulaValue) <> &quot;&quot; then
(
if trim(right(FormulaValue,5)) =&quot;&quot; Then
(

FormulaValue:=left(FormulaValue,len(FormulaValue)-5);
);
);
FormulaValue:= FormulaValue & CheckStr & chr(13) & chr(10) & &quot; &quot;;
for loopJ:= 1 to ubound(x) do
(
TempArray:=split(x[loopJ],&quot;\&quot;);
if (trim(CheckStr) = trim(TempArray[1])) then
(
Remdash = Instr(TempArray[2],&quot;-&quot;);
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 & &quot; &quot; ;
);
);

);
);
);
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

 
Dear NoteGuy1,

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},&quot; &quot;,-1) else MakeArray(&quot; &quot;,&quot; &quot;);

StringVar Array l;
redim preserve l[2];
l := if not isnull({Incident.Last Name}) then Split ({Incident.Last Name},&quot; &quot;,-1) else MakeArray(&quot; &quot;,&quot; &quot;);
//end array for suffix in last name

FName := n[1] + &quot; &quot;;
MName := if ubound(n) = 2 then n[2] + &quot; &quot; else &quot;&quot;;
LName := L[1] + &quot;, &quot;;
Suffix := if ubound(l) = 2 then l[2] else &quot;&quot;;

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, Microflo provides expert consulting on MagicTSD and Crystal Reports.
 
I was having the same sort of problem: I was using a for loop to search the array, and I was getting the &quot;A subscript must be between 1 and the size of the array&quot; message on a sporadic basis. I think, of course you can only guess about these formulas because there is no way to step into them, that the problem was due to my having an empty array. In other words, when I created the array I put no items in it. To fix this problem, I just added an empty string when I initialize the array, so that I am sure to have at least one item. That seems to have resolved the issue.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top