Found a max value on an array

Found a max value on an array

Postby Silvio.Falconi » Fri Mar 20, 2020 5:41 pm

When I insert a product I add an array

aadd(aColBtn,{nItem,ncolSer} )


Image


nItem is the number of Item and mColSer is the colum where I show the product

before to show the product I try to search the value of ncolSer on array aColBtn

If Len(aColBtn) >0
nColser:= ascan( aColBtn, {|e| e[1] = nItem})
If nColser=0
ncolSer:=200
Endif
else
ncolSer:=200
endif


the problem is the procedure found the nItem but take the first of the array with same nItem and not that having the max value

then I thinked to make another test
I when save on array aColBtn I must erase all records having the same nItem


adel( aColBtn, {|e|e[1] = nItem},.t.)

and I can save the current value

aadd(aColBtn,{nItem,ncolSer} )

but not run
because adel erase all records why ?
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: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Re: Found a max value on an array

Postby cnavarro » Fri Mar 20, 2020 8:35 pm

Make an ASort of the array by the column that contains the values to order and get the last element after ordering it.
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6549
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Found a max value on an array

Postby Silvio.Falconi » Sat Mar 21, 2020 4:48 pm

I resolve with

nCheck:= ascan( aColBtn, {|e| e[1] = nItem})
IF nCheck >0
nColser:=aColBtn[nCheck][2]
nColser+=10
adel( aColBtn, ncheck,.t.)
else
nColser := 200
Endif
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: 7075
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 94 guests