Sort array but not typical from A-Z or Z-A

Sort array but not typical from A-Z or Z-A

Postby Marc Venken » Mon Aug 31, 2020 6:49 pm

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
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1397
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Sort array but not typical from A-Z or Z-A

Postby Otto » Mon Aug 31, 2020 7:32 pm

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.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6254
Joined: Fri Oct 07, 2005 7:07 pm

Re: Sort array but not typical from A-Z or Z-A

Postby Marc Venken » Mon Aug 31, 2020 7:35 pm

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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1397
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Sort array but not typical from A-Z or Z-A

Postby nageswaragunupudi » Tue Sep 01, 2020 12:10 pm

Code: Select all  Expand view
#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
User avatar
nageswaragunupudi
 
Posts: 10465
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Sort array but not typical from A-Z or Z-A

Postby Marc Venken » Tue Sep 01, 2020 3:28 pm

Super !! Works as wanted
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1397
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 41 guests