Brian Dunning's FileMaker Custom Functions

CombineValues ( list1 ; list2 )

Combines two lists of values, sort of like php's array_combine function

  Average rating: 4.4 (39 votes) Log in to vote

Jonathan Stark   Jonathan Stark - Show more from this author
Jonathan Stark Consulting
http://jonathanstark.com/

Share on Facebook Share on Twitter

  Sample input:
list1="x¶y¶z"
list2="2¶4¶8"
  Sample output:
x=2
y=4
z=8

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

CombineValues can be used to mimic the behavior of creating an associate array in php. List1 becomes the "Keys" and List2 becomes the "Vals".

I wrote it to be used in conjunction with a Let statement, wrapped in an Evaluate statement to parse incoming script parameters into local script variables.

With minor mods, you can alter the delimiters and output format to suit your taste - I left it really generic.

ciao!

 

Comments

Tom Vincent   Tom Vincent, Nearly Normal Services
May 6, 2011
Simple, elegant, just the thing I'd have come up with after seven or eight rewrites and a couple of late nights. (We may have similar coding esthetics.)

And embarrassingly, I only needed it for a Tool Tip.

Thank you.
 
Hudi   Hudi, NY
Dec 10, 2014
Fantastic! Was in a bind with this one when I found it. Many thanks
 
Adam Dempsey   Adam Dempsey, UK
Jul 10, 2018
I've tweaked this slightly, adding a delim param (I wanted a space) and fixed it adding an extra line return at the end.


CombineValues ( list1 ; list2 ; delim )

If(
( ValueCount( list1 ) = 0 ) or ( ValueCount( list2 ) = 0 );
"";
GetValue( list1; 1 ) & delim & GetValue( list2; 1 ) &
If(
Length( GetValue( list1; 2 ) ) > 0 and
Length( GetValue( list2; 2 ) ) > 0;
¶
) &
CombineValues (
RightValues( list1; ValueCount( list1 ) - 1 );
RightValues( list2; ValueCount( list2 ) - 1 );
delim
)
)
 

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