Search code examples
filemaker

filemaker implode array


So lets say my calculation is this

Let (
    [
        $result[1] ="1";
        $result[2] ="!";
        $result[3] = "3";
        $result[4] = "4";
        $result[5] = "5";
        $result[6] = "6";
        $result[7] = "7";
        $result[8] = "8";
        $result[9] = "-";
        $result[10] = "10";
        $result[11] = "11";
        $result[12] = "12";
        $result[13] = "13";
        $result[14] = "14";
        $result[15] = "15";
        $result[16] = "!";
    ];  
    $result[1] & 
    $result[2] & 
    $result[3] & 
    $result[4] & 
    $result[5] & 
    $result[6] & 
    $result[7] & 
    $result[8] & 
    $result[9] & 
    $result[10] & 
    $result[11] & 
    $result[12] & 
    $result[13] & 
    $result[14] & 
    $result[15] &
    $result[16]
)

this is pretty straight forward I make and array and then I want to it to return the array as a string is there and easier way to concatenate the the values of the result array ?

** Sample custom functions *** trying to use @chuck 's code not sure what I'm doing wrong I could figure out how to upload a file so here are some mimages

enter image description here enter image description here enter image description here


Solution

  • Here's two custom functions that should work if you can assume that once you get to a blank value in the array, you've reached the end of the array. I wrote it very quickly and only tested it once, but perhaps it'll do the job for you.

    ConcatArray( VarName ) = _ConcatArray( VarName; 1 )

    This just calls a recursive function with an initial value.

    _ConcatArray( VarName; Iteration ) = Let(
      [
        Var = Evaluate( "$" & VarName & "[" & Iteration & "]" )
      ];
    
      Case(
        IsEmpty( Var );
        "";
        Var & _ConcatArray( VarName; Iteration + 1 )
      )
    )
    

    I then opened the Data Viewer in FileMaker and tested it with this calculation.

    Let (
        [
            $result[1] ="1";
            $result[2] ="!";
            $result[3] = "3";
            $result[4] = "4";
            $result[5] = "5";
            $result[6] = "6";
            $result[7] = "7";
            $result[8] = "8";
            $result[9] = "-";
            $result[10] = "10";
            $result[11] = "11";
            $result[12] = "12";
            $result[13] = "13";
            $result[14] = "14";
            $result[15] = "15";
            $result[16] = "!"
        ];  
        ConcatArray( "result" )
    )
    

    The result was 1!345678-101112131415!.