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
Asort array base two elements and found the last number
- Silvio.Falconi
- Posts: 4956
- Joined: Thu Oct 18, 2012 7:17 pm
Asort array base two elements and found the last number
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
- MarcoBoschi
- Posts: 925
- Joined: Thu Nov 17, 2005 11:08 am
- Location: Padova - Italy
- Contact:
Re: Asort array base two elements and found the last number
Silvio,
Try RASCAN
Try RASCAN
Code: Select all
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
info@marcoboschi.it
- Silvio.Falconi
- Posts: 4956
- Joined: Thu Oct 18, 2012 7:17 pm
Re: Asort array base two elements and found the last number
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
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC