ValuePosition ( valuelist ; searchvalue )
Get position number of the search value from the value list
Average rating: 4.2 (30 votes) Log in to vote
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
This CF gives you the position number of the search value from the given value list ( array separated by ¶ ).
Jun 3, 2014
|ValuePosition ( "a¶b¶c¶b¶a" ; "a" ) = 5; and ValuePosition ( "a¶b¶c¶b¶a" ; "b¶c" ) returns empty!?
But then it's not necessary to employ a recursive mechanism for finding the index of the first occurrence; simply use
ValueCount ( Left ( valuelist ; Position ( valuelist ; searchvalue ; 1 ; 1 ) ) )
found = Case ( lastvalue = search ; True ; False )
is the same as
found = lastvalue = search
exist = Case ( PatternCount ( list ; search ) = False and not IsEmpty ( search ) ; False ; True )
exist = PatternCount ( list ; search )
|Michael Bijnens, Belgium
Jun 4, 2014
As you can see my CF name = ValuePosition and not ValuePositionS.
So its not made for more multi value searches.
Try your simple example with numbers like ( 53 , 353, 121, 12 ).
I have tried it in many different ways but it is not waterproof so thats why I use a recursive function.
Jun 4, 2014
Try your simple example with numbers like ( 53 , 353, 121, 12 )
you're right, I forgot a little detail; change it to
ValueCount ( Left ( valuelist ; Position ( ¶ & valuelist & ¶ ; ¶ & searchvalue & ¶ ; 1 ; 1 ) ) )
and that'll give you exactly the same functionality without recursion.
Also, note that your CF returns the last position, not the first one.
|Late to the party, Shanghai
Jan 8, 2016
|// I like to use this:
ValuePosition( _valuelist; _value )
_valuelist: a return-delimited string of values;
_value: a single-line string.
an integer identifying the listed position of (the first occurrence of) _value within _valuelist,
or 0, whenever the _value is not listed.
// return zero when no match occurs:
IsEmpty( FilterValues( _valuelist; _value ) ); 0;
// FileMaker 15 should provide something like this function for us, but doesn't …
// first, bracket the arguments supplied with "¶"s:
_valuelist = "¶"&_valuelist&"¶";
_value = "¶"&_value&"¶";
// locate the "¶" character immediately preceding (the first occurrence of) _value:
_position = Position( _valuelist; _value; 1; 1 );
// extract all the return characters BEFORE this _position:
_returns = Filter( Left( _valuelist; _position ); "¶" );
// how many are there?
_valuePosition = Length( _returns )
|Michael Kupietz, United States
Nov 18, 2017
|valuePosition ( "AB¶BC¶CD","B" ) returns an out-of-memory error due to runaway recursion.|
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.