Found a max value on an array

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Found a max value on an array

Post by Silvio.Falconi »

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 ?
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Found a max value on an array

Post by cnavarro »

Make an ASort of the array by the column that contains the values to order and get the last element after ordering it.
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Found a max value on an array

Post by Silvio.Falconi »

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
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
Post Reply