Page 1 of 1

Sorting An Arrau

Posted: Fri Oct 12, 2012 9:03 am
by omni
Roger,

Doing a printout, hundreds of pages. There are 50-100 detail types, and at the end the detail type totals are listed. User wants to be alpha. The type and amount are in an array.

How can I sort it?

Could not find anything on this except the one used for browses.

Thanks

Fred
Omni

Re: Sorting An Arrau

Posted: Fri Oct 12, 2012 10:23 am
by GeneB
From the Xbase++ help for Asort() .......

// Sort a two dimensional array

// The example shows the ascending and descending sorting of a
// two dimensional array.

PROCEDURE Main
LOCAL aArray

aArray := { ;
{"E", 4 }, ;
{"A", 3 }, ;
{"D", 2 }, ;
{"C", 5 }, ;
{"B", 1 } ;
}

// first column ascending sort
ASort( aArray,,, {|aX,aY| aX[1] < aY[1] } )

// aArray is: { {"A", 3 }, ;
// {"B", 1 }, ;
// {"C", 5 }, ;
// {"D", 2 }, ;
// {"E", 4 } }

// second column descending sort
ASort( aArray,,, {|aX,aY| aX[2] > aY[2] } )
// aArray is: { {"C", 5 }, ;

// {"E", 4 }, ;
// {"A", 3 }, ;
// {"D", 2 }, ;
// {"B", 1 } }

RETURN