FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour search a big value on an array
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
search a big value on an array
Posted: Wed Nov 18, 2020 11:31 AM

If I have this array

aData:= { {"B", 0.2, 0.1 ,3.6 ,0.7},;
{"T", 0.2, 0.75 ,3.6 ,0.5},;
{"T", 0.2, 1.2 ,3.6 ,0.4},;
{"T", 0.2, 1.6 ,3.8 ,0.4},;
{"T", 0.2, 1.6 ,3.6 ,0.4},;
{"T", 0.2, 1.6 ,3.6 ,0.4} }

I would like to find the largest number of the 4th array column ( adata[n][4])

how I must make ?
thanks

I made

nHeightold:= adata[1][4]

For n= 1 to Len(adata)
If adata[n][4]>nHeightold
nHeightBig:= adata[n][4]
nHeightold:= adata[n][4]
Endif

next

but I believe there is a better method

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: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: search a big value on an array
Posted: Wed Nov 18, 2020 10:24 PM

Silvio,

Why don't you sort the array first

aData := ASort(aData,,,{|x,y| (x[4]>y[4]})

The largest number is in adata[1,4].

Regards,

Michel D.
Genk (Belgium)


_____________________________________________________________________________________________

I use : FiveWin for (x)Harbour v. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: search a big value on an array
Posted: Fri Nov 20, 2020 08:24 PM

local nValMayor := 0, nCol := 4
AEval( aData, {|a| if( a[nCol] > nValMayor, (nValMayor := a[nCol], ) } )

Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql

Continue the discussion