FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Found a max value on an array
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Found a max value on an array
Posted: Fri Mar 20, 2020 05:41 PM
When I insert a product I add an array

aadd(aColBtn,{nItem,ncolSer} )





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 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: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Found a max value on an array
Posted: Fri Mar 20, 2020 08: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
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM
Re: Found a max value on an array
Posted: Sat Mar 21, 2020 04: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 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