InsertValue ( valueList ; index ; value )
Reliable insertion/replacement of values in a value list
Average rating: 5.0 (1 vote) Log in to vote
Stephan Casas - Show more from this author
http://www.stephancasas.com |
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
Technical Contact: Stephan Casas
Most proposed insertion functions work by counting and calculating the number of pilcrow (¶) chars in a list and then using some combination of text function (Left(), Position(), Right(), etc.) to build the output around the desired insertion. This has several problems and tends to be unreliable.
This function creates a series of nested Let() functions which increment nested variable declaration at evaluation. Such a series is possible by exercising the mathematic formula (10 ^ nth - 1), which will yield any desired number of character repetitions which can then be replaced by a Substitute() function.
After writing the nested Let() functions to the evaluation stream, the function then writes the series of closing parenthesis characters necessary to create a balanced calculation.
Once evaluation takes place, each nested loop function checks that the value of 'i' is not equivalent to the desired insertion index. When it is, rather than writing the value from the supplied list, it writes the replacement value into the output stream.
This function will work on an empty value list and will work when the insertion index exceeds the value list count. No additional, unexpected, or extraneous pilcrow (¶) chars are appended to the output.
Comments
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.