INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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.

Jobs

Array Sort order

Array Sort order

(OP)
thread767-1553861: Sorting Summary labels in an array

???? //-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] + ", " //-1 for ascending order
);
trim(left(y,len(y)-2));

RE: Array Sort order

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.

RE: Array Sort order

(OP)
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 !!!

RE: Array 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

RE: Array Sort order

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

RE: Array Sort order

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

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!

Resources

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