Brian Dunning's FileMaker Custom Functions

ProcessList ( ListIn ; TestFunction ; OutputFormat ; EvaluateOutput ; FinalFunction )

A multipurpose custom function to filter & process a list of values

  Be the first to rate this function Log in to vote

Warren Jones   Warren Jones - Show more from this author
Wasabi Data Solutions
https://wasabidatasolutions.com

Share on Facebook Share on Twitter

  Sample input:
ProcessList( "Black cat¶Brown dog¶White cat¶Black dog¶Red dog¶Black bird¶Orange cat" ; "not PatternCount( [v] ; \"cat\" )" ; "[v]" ; False ; "[oc] & \" of \" & [ic] & \" (\" & Round( [oc]/[ic] * 100 ; 1 ) & \"%) are not cats\"" )
  Sample output:
Brown dog
Black dog
Red dog
Black bird
4 of 7 (57.1%) are not cats

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

PURPOSE:
A multipurpose custom function to process a list of values with the following operations…
1. Perform a test on each value as to whether to retain in the output list
2a. Format the output values according to a format string, or
2b. Evaluate a user-supplied function on each value or iteration number
3. Evaluate a user-supplied final function to append an extra value to the output list.
See examples below.

REQUIREMENT:
FileMaker Pro 18+ (uses 'While' function)

Created by: Warren Jones, WasabiDataSolutions.com
Created: 2022-09-11
Last Edit: 2022-09-29


PARAMETERS:
ListIn: The input list of values
TestFunction: A function to applied to each value to detemine if it should be output (text format, should return a Boolean result (T/F). If TestFunction is empty will default to include each value.
OutputFormat: A text string which is either a) used to format the output value, or b) a function to be evaluated for each output value
EvaluateOutput: Boolean to enable evaluation of the OutputFormat parameter
FinalFunction: An optional text string to be evaluated to append an additional or summary value in the list

Available substitutions for TestFunction
"[i]" the input iteration number
"[v]" the i'th value of the list

Available substitutions for OutputFormat
"[i]" the input iteration number
"[ic]" the count of the input values
"[o]" the output interation number
"[oc]" the count of the output values
"[v]" the i'th value of the list

Available substitutions for FinalFunction
"[ic]" the count of the input values
"[oc]" the count of the output values


EXAMPLES:
( using ListIn = "Black cat¶Brown dog¶White cat¶Black dog¶Red dog¶Black bird¶Orange cat" )

Example 1: (Unchanged list)
ProcessList( ListIn ; "" ; "[v]" ; false ; "" )
Returns:
Black cat
Brown dog
White cat
Black dog
Red dog
Black bird
Orange cat


Example 2: (Format values)
ProcessList( ListIn ; "" ; "[i] - [v]" ; False ; "" )
Returns:
1 - Black cat
2 - Brown dog
3 - White cat
4 - Black dog
5 - Red dog
6 - Black bird
7 - Orange cat


Example 3: (Filter cats)
ProcessList( ListIn ; "PatternCount( [v] ; \"cat\" )" ; "[v]" ; False ; "" )
Returns:
Black cat
White cat
Orange cat


Example 4: (Filter & format)
ProcessList( ListIn ; "PatternCount( [v] ; \"cat\" )" ; "[o] of [oc] [v] is a cat." ; False ; "" )

Returns:
1 of 3 Black cat is a cat.
2 of 3 White cat is a cat.
3 of 3 Orange cat is a cat.


Example 5: (Filter & format)
ProcessList( ListIn ; "PatternCount( [v] ; \"black\" )" ; "[i] of [ic] [v] is lucky." ; False ; "" )

Returns:
1 of 7 Black cat is lucky.
4 of 7 Black dog is lucky.
6 of 7 Black bird is lucky.


Example 6: (Format and Process values with function)
ProcessList( ListIn ; "" ; "\"[i] - \" & UPPER(\"[v]\")" ; True ; "" )

Returns:
1 - BLACK CAT
2 - BROWN DOG
3 - WHITE CAT
4 - BLACK DOG
5 - RED DOG
6 - BLACK BIRD
7 - ORANGE CAT


Example 7: (Filter and summarise)
ProcessList( ListIn ; "not PatternCount( [v] ; \"cat\" )" ; "[v]" ; False ; "[oc] & \" of \" & [ic] & \" (\" & Round( [oc]/[ic] * 100 ; 1 ) & \"%) are not cats\"" )

Returns:
Brown dog
Black dog
Red dog
Black bird
4 of 7 (57.1%) are not cats


Example 8: (Show every second value with bullet)
ProcessList( ListIn ; "Mod( [i] ; 2 ) = 0 " ; "● [v]" ; False ; "" )
● Brown dog
● Black dog
● Black bird

Example 8: (Show no values, only summary)
ProcessList( ListIn ; "PatternCount( [v] ; \"cat\" )" ; "" ; False ; "[oc] & \" of \" & [ic] & \" (\" & Round( [oc]/[ic] * 100 ; 1 ) & \"%) are cats\"" )
Returns:
3 of 7 (42.9%) are cats

 

Comments

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 18 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: