Page 1 of 1
Sort array but not typical from A-Z or Z-A
Posted: Mon Aug 31, 2020 6:49 pm
by Marc Venken
Helllo,
I need to sort lots of datalines not a typical way...
I get the charStrings like
cVar = "S,M,XL,L,2X,3X" this is comming from a loop reading a database
I put them in a array, but then the array should sort always with this as possible result.
aResult = "S,M,L,XL,2X,3X" it is possible that cVar has only 3 items cVar = "M,S,XL" and aResult should be "S,M,XL"
"XS,S,M,L,XL,2X,3X,4X,5X" are the options that can be found...
How can it be done ? Asort = different
Re: Sort array but not typical from A-Z or Z-A
Posted: Mon Aug 31, 2020 7:32 pm
by Otto
Marc, couldn't you insert an additional field.
Or a function "XS, S, M, L, XL, 2X, 3X, 4X, 5X" where you replace XS with A, S with B, etc and then sort and then reset.
Re: Sort array but not typical from A-Z or Z-A
Posted: Mon Aug 31, 2020 7:35 pm
by Marc Venken
Otto wrote:Marc, couldn't you insert an additional field.
Or a function "XS, S, M, L, XL, 2X, 3X, 4X, 5X" where you replace XS with A, S with B, etc and then sort and then reset.
Good idea...
Re: Sort array but not typical from A-Z or Z-A
Posted: Tue Sep 01, 2020 12:10 pm
by nageswaragunupudi
Code: Select all
#include "fivewin.ch"
function Main()
local oDlg, oFont
local cVar := PadR( "S,M,XL,L,2X,3X", 25 )
DEFINE FONT oFont NAME "VERDANA" SIZE 0,-18
DEFINE DIALOG oDlg SIZE 400,200 PIXEL TRUEPIXEL FONT oFont
@ 20, 20 SAY "Text :" SIZE 70,26 PIXEL OF oDlg
@ 70, 30 SAY "Result :" SIZE 70,26 PIXEL OF oDlg
@ 20,100 GET cVar PICTURE "@!" SIZE 280,30 PIXEL OF oDlg VALID ( oDlg:Update(), .T. )
@ 70,100 SAY { || MySortFunc( cVar ) } SIZE 280,24 PIXEL OF oDlg UPDATE
@ 120,280 BUTTON "CLOSE" SIZE 100,30 PIXEL OF oDlg ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
//----------------------------------------------------------------------------//
function MySortFunc( cVar )
local cOrder := ",XS,S,M,L,XL,2X,3X,4X,5X,"
local aVar, cRet
aVar := FW_ListAsArray( CharRem( " ", AllTrim( cVar ) ) )
ASort( aVar, nil, nil, { |x,y| At( "," + x + ",", cOrder ) < At( "," + y + ",", cOrder ) } )
return FW_ArrayAsList( aVar )
//----------------------------------------------------------------------------//
Re: Sort array but not typical from A-Z or Z-A
Posted: Tue Sep 01, 2020 3:28 pm
by Marc Venken
Super !! Works as wanted