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

Array Sort order

Status
Not open for further replies.

Ianmadi

Technical User
Mar 3, 2005
4
GB
thread767-1553861

???? //-1 for ascending order ??????

This code is great but I can't get it Ascending !!!! I have put -1 in various places and it gives error

WhilePrintingRecords;
stringvar Array codes := split({@array}, ", ");
stringvar Array result;
redim preserve result[ubound(codes)];
Numbervar k;
NumberVar p;
stringvar y;
numbervar i;

for k := 1 to ubound(codes) do
(
result[k] := trim(Maximum(codes));
for p := 1 to ubound(codes) do
(
if trim(codes[p]) = result[k] then
(
codes[p] := "";
Exit For;
);
);
);

for i := 1 to ubound(result) do (
y := y + result[-i] + ", " [highlight #CC0000]//-1 for ascending order[/highlight]
);
trim(left(y,len(y)-2));
 
I have not examined this code. But I found some code for a bubble sort (VBA) and converted to Crystal format. It will only work with strings. I will have to find the code.
 
Ideal I have a Stringvar anyway but all it does id show in the descending order the I changed to his code and its still descending
effectively I have a Multi-value Dynamic Paramenter, that I use, then select data from another table related to it Everything is perfect except the sort order !!!

 
My fault. The comment should have read:

//-i for ascending order

...in other words, the formula will sort in ascending order as is. For descending order, remove the minus sign.

-LB
 
Thanks but that gives me a problem because as written if is ascending but my records are still not sorting and if I change it to I then it still doesn't work back to the drawingboard

this is my full code and it takes the list of multi value parameter and I need it in order

shared numbervar counter;
shared stringvar display;
for counter := 1 to count({?Pm-?Enter invoice Numbers}) do
(
display := display + totext({?Pm-?Enter invoice Numbers}[counter],0,"") + ", ";
);

stringvar Array codes :=display;
stringvar Array result;
redim preserve result[ubound(codes)];
Numbervar k;
NumberVar p;
stringvar y;
numbervar i;

for k := 1 to ubound(codes) do
(
result[k] := trim(Maximum(codes));
for p := 1 to ubound(codes) do
(
if trim(codes[p]) = result[k] then
(
codes[p] := "";
Exit For;
);
);
);

for i := 1 to ubound(result) do (
y := y + result[-i] + ", " //-1 for ascending order
);
trim(left(y,len(y)-2));
 
Make two changes:

shared numbervar counter;
shared stringvar display;
for counter := 1 to count({?parm}) do
(
display := display + {?parm}[counter] +
if counter <> ubound({?parm}) then ", "; //this removes the final, in display
);

WhilePrintingRecords;
stringvar Array codes := split(display,", "); //you need to split display so that it is still an array

The rest of the formula is correct. Please remove the comment at the end or change the -1 to -i, just so it is not confusing to others who might read this.
-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top