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!

How can I sort an array alphabetically? 1

Status
Not open for further replies.

DOJRich

Technical User
Oct 12, 2009
1
0
0
AU
I have a comma separated list of locations in the report footer of my report.
This formula is in the details section:

WhilePrintingRecords;
stringvar array locarr;
numbervar i;
if not({AUDIT.LOCATION} in locarr) then
(
i := i + 1;
redim preserve locarr;
locarr := {AUDIT.LOCATION};
);
locarr

And this formula is in the Report Footer:

WhilePrintingRecords;
stringvar array locarr;
stringvar fin;
numbervar j;
numbervar n;
for j := 1 to ubound(locarr) do
fin := fin + locarr[j] + ", ";
left(fin,len(fin)-2);

The problem is that the results are printed in the order they were put into the array. How can I sort the array so that when it prints the results, the locations are in alphabetical order?

Thanks.
 
You would need to create a sort routine for the array. There are lot of different ways of sorting.
 
Using Bubble sort:

whileprintingrecords;
stringvar array MyValues := locarr;
numbervar i;
numbervar j;
stringvar temp;
for i:=1 to ubound(MyValues)-1 do (
for j:=1 to ubound(MyValues)-i do(
if MyValues[j] > MyValues[j+1] then (
temp := MyValues[j];
MyValues[j] := MyValues[j+1];
MyValues[j+1] := temp;
)
)
);
join(MyValues,", ")
 
That is a well written little routine. Would you mind if I posted it on my blog? Happy to give you credit based on your TT handle or name.

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guides to Formulas, Parameters, Subreports, Cross-tabs, VB, Tips and Tricks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top