FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Asort array base two elements and found the last number
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Asort array base two elements and found the last number
Posted: Sun Mar 22, 2020 01:06 AM

Dear friends,

I must found the last number (field 1) of this array if the cCode ( field 2) is "01"

Local aData:= { ;
{4,"01","17/03/2020","17/03/2020"} ,;
{7,"02","17/03/2020","18/03/2020"} ,;
{7,"01","17/03/2020","18/03/2020"} ,;
{11,"02","17/03/2020","18/03/2020"} ,;
{8,"01","17/03/2020","18/03/2020"} }

local cCodice:="01"

I try with

ASort( aData ,,, {|x,y| If ( x[2] == cCodice, x[1]< y[1],) } )

How I can make to found the last value for the code "01" ?

it must return me 8

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Asort array base two elements and found the last number
Posted: Sun Mar 22, 2020 07:31 AM
Silvio,
Try RASCAN
Code (fw): Select all Collapse
FUNCTION MAIN()
LOCAL x , y  , nPos
LOCAL aData:= { { 4 ,"01" , "17/03/2020" , "17/03/2020" } , ;
                { 7 ,"02" , "17/03/2020" , "18/03/2020" } , ;
                { 7 ,"01" , "17/03/2020" , "18/03/2020" } , ;
                {11 ,"02" , "17/03/2020" , "18/03/2020" } , ;
                { 8 ,"01" , "17/03/2020" , "18/03/2020" } }

LOCAL cCodice:="01"


ASORT( aData ,,, {|x,y| If ( x[2] == cCodice, x[1]< y[1],) } )

FOR x := 1 TO LEN( aData )
    ? aData[ x , 1 ] , aData[ x , 2 ] ,aData[ x , 3 ] ,aData[ x , 4 ]
NEXT x

nPos := RASCAN( aData, { | aData| aData[ 2 ] = cCodice } )

? nPos , aData[ nPos , 1 ] , aData[ nPos , 2 ] ,aData[ nPos , 3 ] ,aData[ nPos  , 4 ]

RETURN NIL
Marco Boschi
info@marcoboschi.it
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: Asort array base two elements and found the last number
Posted: Sun Mar 22, 2020 10:38 AM

thanks, I understood that I am doing something bigger than my abilities and when I have a problem that is easy for you it becomes difficult for me, perhaps because the mind is occupied by other thoughts and worries and I do not find the right solution

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion