One Part Harmony – FileMaker Database Design, Development, and Maintenance

Custom Functions: Value Lists & Script Parameters
Extend_Value

Generates a string containing the given value, repeated the specified number of times.

Among other uses, this function can be invoked by the
Update_Value function to generate a string of return characters for use when adding a value to a location past the current end of the value list (i.e. adding the 100th value to a value list currently containing only 50 items, where 49 returns are needed to pad the end of the value list before the new value is appended).

Format
Extend_Value( Value , Number )
Parameters
Value - The character or string to be repeated
Number - The number of repetitions desired
Data Type Returned
Text
Examples
Extend_Value( “¶” , 10 ) returns ¶¶¶¶¶¶¶¶¶¶
Description
Because custom functions cannot employ any looping constructs, this function employs recursion to create a string containing the given value, repeated the specified number of times. Subsequent iterations after the first are passed some temporary data by appending a delimiter character followed by the temporary data to the Number parameter. If the functions sees that this additional information has been appended to the Number parameter, it knows this is not the first iteration and can perform accordingly.
FileMaker Versions Supported
7, 8, 8.5, 9, 10, 11, 12, 13, 14, 15, 16
Code
/*
This function employs recursion to create a string containing the
given value, repeated the specified number of times.

Among other uses, this function can be invoked by the Update_Value
function to generate a string of return characters for use when
adding a value to a location past the current end of the value list
(i.e. adding the 100th value to a value list currently containing only
50 items, where 49 returns are needed to pad the end of the value
list before the new value is appended).
*/

Let
(
[

Separator Pos = Position( Number ; "|" ; 1 ; 1 ) ;

Original Value = If( Separator Pos > 0 ; Right( Number ; Length( Number ) - Separator Pos ) ; Value ) ;

Number = If( Separator Pos > 0 ; Left( Number ; Separator Pos - 1 ) ; Number )

] ;

Case
(
/*
first iteration and Number = 0 (nothing to do, so we're done
*/
Number = 0 ; "" ;

/*
first iteration is the only one requested, so set string to Value and we're done
*/
Number = 1 and Separator Pos = 0 ; Value ;

/*
last of some number of subsequent iterations so append specified Value to string and we're done
*/
Number = 1 ; Value & Original Value ;

/*
a subsequent iteration (but not the last) so add specified Value to string and invoke self for next iteration
*/
Separator Pos > 0 ; Extend_Value( Value & Original Value ; ( Number- 1 ) & "|" & GetAsText( Original Value ) ) ;

/*
first iteration (but not the last) so initialize text string with specified Value and invoke self for next iteration
*/
Extend_Value( Value ; ( Number - 1 ) & "|" & Original Value )
)

)