SortValues ( list ; sortAscending )
Sorts the values in a list ascending or descending
Average rating: 3.8 (39 votes) Log in to vote
Theo Ros - Show more from this author |
SortValues ( "apple¶grape¶banana" ; False )
grape¶banana¶apple
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
Returns the list with items sorted
Syntax: SortValues ( list ; sortAscending )
In: list - the return delimited list to search
sortAscending - if True (1), the list will be sorted Ascending,
if False (0), the sorting is Descending
Return type: Text
SortValues ( "apple¶grape¶banana" ; True ) --> "apple¶banana¶grape"
SortValues ( "apple¶grape¶banana" ; False ) --> "grape¶banana¶apple"
This sort uses functions MinValue() and MaxValue()
Comments
David Apr 2, 2009 |
||
"List" is now a built in function so the "list" parameter needs to be edited and given a different name. The same applies to MinValue and MaxValue custom functions. Thanks for the work though. It solved mt little problem!! |
||
Vaughan, Sydney, Australia Aug 22, 2011 |
||
/* -------------------------------------------------------------------------------- Returns the list with items sorted Syntax: SortValues ( lst ; sortAscending ) In: lst - the return delimited list to search sortAscending - if True (1), the list will be sorted Ascending, if False (0), the sorting is Descending Return type: Text SortValues ( "apple¶grape¶banana" ; True ) --> "apple¶banana¶grape" SortValues ( "apple¶grape¶banana" ; False ) --> "grape¶banana¶apple" This sort uses functions MinValue() and MaxValue() Theo Ros -------------------------------------------------------------------------------- */ If ( ValueCount ( lst ) ; // first make sure that the lowest or highest value and the list itself end with return Let ( [ val = If ( sortAscending ; MinValue ( lst; "" ) ; MaxValue ( lst ; "" ) ) & "¶" ; lst = If ( Right ( lst ; 1 ) <> "¶" ; lst & "¶" ; lst ) ; // find and replace just 1 occurrence of the found value rest = Replace ( lst ; Position ( lst ; val ; 1 ; 1) ; Length ( val ) ; "" ) ] ; // finally remove any leading or trailing returns from the list LeftWords ( val & SortValues ( rest ; sortAscending ) ; 999999999 ) ) ) |
||
YK, JAPAN Mar 14, 2016 |
||
Thank you. I could learn a lot from scripts in this site. In this custom function, the last parentheses disappeared. LeftWords ( "XXXX(xxxx)" ; 999999999 ) = "XXXX(xxxx" |
||
Danny R, western Washington Jan 23, 2018 |
||
Tried to use this to reverse a value list. Keeps telling me to add +,-,; etc. characters after "MinValue" Am I doing something wrong? | ||
Danny R, western Washington Jan 23, 2018 |
||
nm. Figured it out. | ||
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.