Thanks Rex... I just created a little routine to do this also. I thought that it might have been built in to the Unibasic language. Anyways, here is the code I came up with (not fully tested) if anyone is interested...
SUBROUTINE QSORT(ARRAY, ATTRIBUTE.LIST, MAIN.SORT, SORT.TYPE, ERR) * ************************************************************************ * ARRAY - This is the dynamic array iwth the attributes that needs to be sorted. * ATTRIBUTE.LIST - This is a list of attributes to sort. * MAIN.SORT - This is the main sort attribute position * SORT.TYPE - This is the sort type AL, AR, DL, DR * ERR - This allows the calling routine to handle any errors. ************************************************************************ * MAIN PROGAM: ************************************************************************ * * Initialization HOLD.ARRAY = ARRAY ERR = "" * * Setup checks. LOCATE MAIN.SORT IN ATTRIBUTE.LIST<1> SETTING POS ELSE ERR = "Your MAIN.SORT must be included in the ATTRIBUTE.LIST" RETURN END SORT.LIST = "AL":@VM:"AR":@VM:"DL":@VM:"DR" LOCATE SORT.TYPE IN SORT.LIST<1> SETTING POS ELSE ERR = "Your SORT.TYPE must be 'AL', 'AR', 'DL', OR 'DR'" RETURN END * * Clear the values in the HOLD.ARRAY. The HOLD.ARRAY is going to be where we * rebuild the array. NUM.OF.LIST.ATT = DCOUNT(ATTRIBUTE.LIST,@VM) FOR ATTRIBUTE.CNT = 1 TO NUM.OF.LIST.ATT ATTRIBUTE.POS = ATTRIBUTE.LIST<1,ATTRIBUTE.CNT> HOLD.ARRAY<ATTRIBUTE.POS> = "" NEXT ATTRIBUTE.POS * * Restructuring ARRAY to HOLD.ARRAY. NUM.OF.MAIN.SORT.VALUES = DCOUNT(ARRAY<MAIN.SORT>,@VM) FOR SORT.VALUE.POS = 1 TO NUM.OF.MAIN.SORT.VALUES * * Get the first value from the main sorting list and locate it in the new list (HOLD.ARRAY). MAIN.SORT.VALUE = ARRAY<MAIN.SORT,SORT.VALUE.POS> LOCATE MAIN.SORT.VALUE IN HOLD.ARRAY<MAIN.SORT> BY SORT.TYPE SETTING INSERT.POS ELSE NULL * * Loop through the ATTRIBUTE.LIST and load values in HOLD.ARRAY in their new positions. NUM.OF.ATTRIBUTES = DCOUNT(ATTRIBUTE.LIST,@VM) FOR ATTRIBUTE.NUM = 1 TO NUM.OF.ATTRIBUTES ATTRIBUTE.POS = ATTRIBUTE.LIST<1,ATTRIBUTE.NUM> ATTRIBUTE.VALUE = ARRAY<ATTRIBUTE.POS,SORT.VALUE.POS> HOLD.ARRAY = INSERT(HOLD.ARRAY,ATTRIBUTE.POS,INSERT.POS,0,ATTRIBUTE.VALUE) NEXT ATTRIBUTE.NUM NEXT SORT.VALUE.POS * * Load sorted array. IF NOT(ERR) THEN ARRAY = HOLD.ARRAY END * RETURN * ************************************************************************ * END OF QSORT ************************************************************************ 'We act as though comfort and luxury were the chief requirements of life, when all that we need to make us happy is something to be enthusiastic about.' ----- Original Message ---- From: Rex Gozar <[email protected]> To: U2 Users List <[email protected]> Sent: Mon, May 24, 2010 1:27:32 PM Subject: Re: [U2] QSORT (Or something like that) You can find these subroutines on PickWiki.com: CALL ROW2COL(A) ;* flip fields to values CALL QUICKSORT(A, 1, "AR") ;* sort on first value CALL ROW2COL(A) ;* flip back rex _______________________________________________ U2-Users mailing list [email protected] http://listserver.u2ug.org/mailman/listinfo/u2-users _______________________________________________ U2-Users mailing list [email protected] http://listserver.u2ug.org/mailman/listinfo/u2-users
