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

Array sort error within Crystal reports

Status
Not open for further replies.

shircol

MIS
Jun 27, 2008
5
US
I am getting the error "A Subscript must be between 1 and size of the array" when I execute this code in my crystal reports formul-- I am using Crystal 2008

stringvar array POPD;
PopD [1] := totext({POPULATION_DISPLAY.FULL_NAME_SORT});
PopD [2] := totext({POPULATION_DISPLAY.USER_NUMBER_SORT});
PopD [3] := totext({POPULATION_DISPLAY.EMAIL_WORK_SORT});
PopD [4] := totext({POPULATION_DISPLAY.DIVISION_SORT});
PopD [5] := totext({POPULATION_DISPLAY.OPERATING_UNIT_SORT});
PopD [6] := totext({POPULATION_DISPLAY.COUNTRY_NAME_SORT});
numbervar loop1;
numbervar loop2;
stringvar temp;
for loop2:=1 to ubound(POPD)-1 do(
for loop1:=1 to ubound(POPD)-loop2 do(
if POPD[loop1] > POPD[loop1+1] then
(temp := POPD[loop1];
POPD[loop1] := POPD[loop1+1];
POPD[loop1+1] := temp)));
 
Where have you defined initial values of Loop 1 and loop2. If you have not then they will defaul to zero

Thus

if POPD[loop1] > POPD[loop1+1] then
will fail as loop1 = 0

Also you are not incrementing loop2 so both loop 1 & 2 will stay the same value.

Ian
 
I'm not sure what it is you're rying to do in this formula, but you need to assign a size to you POPD array before you can add any values, add this as your second line.

redim POPD[6];

HTH

Gary Parker
MIS Data Analyst
Manchester, England
 
The For loop defines the initial values
for loop2:=1 to ubound(POPD)-1 do

the statement for loop2 :=1 --this starts the loop at 1
 
The solution to add the Redim statement worked!!--thank you
 
You learn something new every day ;-)

I have always defined the start value of my variables.

Ian
 
On the above array sort, when I go to print out the elements in the array, they are not in order:
I am using the following code

whileprintingrecords;
stringvar array PopD;
stringvar element1;
element1:= popd[1];
element1;

any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top