How to find the smallest value of an array of integer ? lazarus / 9-Editor ---------------------------------------------------------------------- GoDxNero · 2010-06-26 15:19 in delphi there is function min(x,y) but this doesnt works in lazarus . Can someone help me ? Prefer with an example. Thanks alots. ---------------------------------------------------------------------- typo · 2010-06-26 17:54 Declare unit Math in the uses clause. ---------------------------------------------------------------------- GoDxNero · 2010-06-27 03:56 Ty it works great  Can you also tell how how I can shorten this line ? Code: [Select]if (distant[x] <= distant[1]) and (distant[x] <= distant[2]) and (distant[x] <= distant[3]) and (distant[x] <= distant[4]) then x = array[1..4]. distant is value for four integers. I wanna get the lowest integer out of those four. Pls help me ---------------------------------------------------------------------- irfanbagus · 2010-06-27 05:07 use minvalue function ---------------------------------------------------------------------- GoDxNero · 2010-06-27 05:43 Like this ? if distant[x.] = MinValue(Distant) then Edit : This work ^^. I got a new probleem thought. If there are 2 or more minvalue that are equals. The program dont know which one to choose. How to solve this ? Example distant[56] is equal to distant[25]. Is there a function to make it always to look for the lower distant with the lowest x ? so distant[25]? ---------------------------------------------------------------------- GoDxNero · 2010-06-27 06:34 I tried break; but no succes :< ---------------------------------------------------------------------- theo · 2010-06-27 07:29 ? What doesn't work? Minvalue does exactly what your subject says. ---------------------------------------------------------------------- irfanbagus · 2010-06-27 07:54 Quote from: GoDxNero on June 27, 2010, 07:43:53 amI got a new probleem thought. If there are 2 or more minvalue that are equals. The program dont know which one to choose. How to solve this ? Example distant[56] is equal to distant[25]. Is there a function to make it always to look for the lower distant with the lowest x ? so distant[25]? what for? if value of distant[56] equal to value of distant[25] then no matter you choose, distant[56] or distant[25], you will get the same value. ---------------------------------------------------------------------- GoDxNero · 2010-06-27 08:00 Quote from: irfanbagus on June 27, 2010, 09:54:28 amQuote from: GoDxNero on June 27, 2010, 07:43:53 amI got a new probleem thought. If there are 2 or more minvalue that are equals. The program dont know which one to choose. How to solve this ? Example distant[56] is equal to distant[25]. Is there a function to make it always to look for the lower distant with the lowest x ? so distant[25]? what for? if value of distant[56] equal to value of distant[25] then no matter you choose, distant[56] or distant[25], you will get the same value. Ye but in my program it cant choose both. The object is suppose to take the shortest path to its closest target. And if there are 2 closest target with the same distant he dont know which path to choose so he will be stuck. like ths : http://i45.tinypic.com/n3uuiu.jpg ---------------------------------------------------------------------- José Mejuto · 2010-06-29 04:42 Quote from: GoDxNero on June 27, 2010, 10:00:30 am[...] Ye but in my program it cant choose both. The object is suppose to take the shortest path to its closest target. And if there are 2 closest target with the same distant he dont know which path to choose so he will be stuck. like ths : http://i45.tinypic.com/n3uuiu.jpg Hello, for ... end is your friend Code: [Select]var   minimun: integer;   location: integer;   j: integer; begin  minimun:=high(integer);  location:=-1;  for j:=0 to high(DistanceArray) do begin   if (DistanceArray[j]