Brian Dunning's FileMaker Custom Functions

MinValue ( lst ; value )

Returns the smallest value in the list

  Average rating: 4.0 (28 votes) Log in to vote

Theo Ros   Theo Ros - Show more from this author

Share on Facebook Share on Twitter

  Sample input:
MinValue ( "apple¶grape¶banana" ; "" )
  Sample output:
apple

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Returns the smallest value in the list

Syntax: MinValue ( list ; value )
In: lst - the return delimited list to search
value - the value currently compared

Return type: Text

MinValue ( "apple¶grape¶banana" ; "" ) --> "apple"

Always start the function off with parameter 'value' = ""

 

Comments

Dwayne Wright   Dwayne Wright, Dwayne Wright
Aug 18, 2010
Initially had troubles because the syntax uses a reserved word "List" (changed to listy as needed)

and

current = Substitute ( value ; "¶" ; "" )

looks like it should be ..

current = Substitute ( currentvalue ; "¶" ; "" )

after making those tweaks, it looks to be working just fine.
 
Theo Ros   Theo Ros, The Netherlands
Aug 19, 2010
Thanks Dwayne for that!

I've updated this function and also the MaxValue function to use "lst" as parameter name instead of "list".

As for the part where it says: current = Substitute ( value ; "¶" ; "" )

that one was correct, because i used the function with the second parameter actually being called "value".

Mistakingly however in the descriptive part (Syntax:) i called it currentValue.
I changed that aswell
 
Westenra   Westenra, Moldova
May 9, 2016
Hi,

I tried to understand and get this to work by renaming
variables, but the results are bogus.

Can you explain what is going on?


/* --------------------------------------------------------------------------------
Returns the smallest value in the lst

Syntax: ShortestString ( lst ; InitStr )
In: lst - the return delimited list to search
InitStr - the value currently compared

Return type: Text

ShortestString ( "apple¶grape¶banana" ; "" ) --> "apple"

Always start the function off with parameter 'InitStr' = ""

Theo Ros
* updated augustus 9, 2010: changed parameter name "list" to "lst"
thanks to Dwayne Wright
-------------------------------------------------------------------------------- */

// If our list contains more than zero elements
If(ValueCount(lst) ;

// Then process:
// Initialize some variables:
Let([
// Select the next value, and strip out carriage return:
CompareStr = Substitute(LeftValues(lst ; 1 ); "¶" ; "" );

// Strip out carriage return:
CurStr = Substitute(InitStr ; "¶" ; "" );

// Set chunk of remaining strings:
RemainderStr = MiddleValues( lst ; 2 ; 9999999999 ) ;

// Which is the smallest string?
SmallStr = Case(IsEmpty(CurStr); CompareStr;
Length(CompareStr) < Length(CurStr) ; CompareStr;
CurStr
) // End Case
]; // End Let

// If there are any strings remaining, recurse on this remainder:
If (ValueCount (RemainderStr); ShortestString(RemainderStr ;
 
Theo Ros   Theo Ros, Hilversum, The Netherlands
May 10, 2016
Hi,

first of, changing variable names is always a good way of figuring out how things work.
In your version, i can some things wrong.

First: you have mistakenly changed the comparison "next < current" into "Length(CompareStr) < Length(CurStr)" which is not correct, because now suddenly you do not compare the values themselves, but their length. This is not what the function is meant for.

Second: In the last part of the function, you have replaced the function name "MinValue" into a non-existing one called "ShortestString". MinValue is NOT a variable name, but the name of this function, so you should not have renamed that.
(what happens there is that the function calls itself for as long as the list has values. This is called Recursion)

Third: i believe you have left out the last part of the function, so now the final If (and also the function as a whole) is not complete.
Your If now is like this:
If (ValueCount (RemainderStr); ShortestString(RemainderStr ;

where it shoud be
If ( ValueCount ( rest ) ; MinValue ( rest ; low ) ; low )

Finally, to close the function after this If, you need to add two extra brackets:

) // End Let
) // End top If


Just one final tip: because in FileMaker all functions start with Capitals, i like to name my variables in camel-case, so they all start with lowercase characters. This helps in recognizing if something is a function name or a variable. ("compareStr", "curStr", etc.)

Hope this helps.

Cheers,
Theo
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: