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
Sort array but not typical from A-Z or Z-A
- Marc Venken
- Posts: 1485
- Joined: Tue Jun 14, 2016 7:51 am
- Location: Belgium
- Otto
- Posts: 6403
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 24 times
- Been thanked: 2 times
- Contact:
Re: Sort array but not typical from A-Z or Z-A
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.
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.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- Marc Venken
- Posts: 1485
- Joined: Tue Jun 14, 2016 7:51 am
- Location: Belgium
Re: Sort array but not typical from A-Z or Z-A
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...
Marc Venken
Using: FWH 23.08 with Harbour
Using: FWH 23.08 with Harbour
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: Sort array but not typical from A-Z or Z-A
Code: Select all | Expand
#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 )
//----------------------------------------------------------------------------//
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Marc Venken
- Posts: 1485
- Joined: Tue Jun 14, 2016 7:51 am
- Location: Belgium
Re: Sort array but not typical from A-Z or Z-A
Super !! Works as wanted
Marc Venken
Using: FWH 23.08 with Harbour
Using: FWH 23.08 with Harbour