×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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?

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

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

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}," ",-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?

I was having the same sort of problem: I was using a for loop to search the array, and I was getting the "A subscript must be between 1 and the size of the array" 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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close