Asort array base two elements and found the last number

Asort array base two elements and found the last number

Postby Silvio.Falconi » Sun Mar 22, 2020 1: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6774
Joined: Thu Oct 18, 2012 7:17 pm

Re: Asort array base two elements and found the last number

Postby MarcoBoschi » Sun Mar 22, 2020 7:31 am

Silvio,
Try RASCAN
Code: Select all  Expand view

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
 
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Asort array base two elements and found the last number

Postby Silvio.Falconi » 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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6774
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Jimmy and 85 guests