Can "min" return the ordinal?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Can "min" return the ordinal?

Post by bjb007 » Mon Mar 17, 2008 4:28 am

I have code like this...

put min(field lblFirst,field lblSecond,field lblThird) into varMin

but I want to know which field holds the minimum value
so I use...

if field lblFirst = varMin then
put 1 into varMin1
end if

etc.

Can the min function return the ordinal (i.e. 1,2,or3)?

I would also like to know if two fields contain the same
number.
Life is just a bowl of cherries.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue Mar 25, 2008 1:01 am

Hi,

This script puts the number of the field with the minimum value into the message box. The script is a bit silly, because it creates two arrays in a repeat loop, but it works.

Code: Select all

on mouseUp
  repeat with x = 1 to 3
    put fld x into myVar[x]
    put x into myVar2[fld x]
  end repeat
  put myVar2[min(myVar)]
end mouseUp
Instead of "put x into myVar2[fld x]", you could also use "put the short name of fld x into myVar2[fld x]" and you could use an if statement to check for a custom property, to make sure that only the values of relevant fields are included.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply