Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

GetValueIndexByPosition (valueList, valueString, matchCase, occurrence, positionLCR)

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.3  (30 votes)
  Discuss this Custom Function

Lewis C. Lorenz, Lorenz Companies
http://www.LorenzCom.com

Retrieve the index of the value in valueList containing the matching valueString.

Sample Input:
GetValueIndexByPosition ("Alpha¶Bravo¶Charlie¶Echo", "charl", False, 1, "L")
GetValueIndexByPosition ("Alpha¶Bravo¶Charlie¶Echo", "charlie", True, 1, "L")
GetValueIndexByPosition ("Daniel¶Danny¶Bill¶daniel¶Frank¶daniel¶Ed", "aniel", True, -2, "R")GetValueIndexByPosition ( "Daniel¶Danny¶Bill¶daniel¶Frank¶daniel¶Ed", "an", False, -2, "C" )
Sample Output:
3
0
4
5


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

Retrieve the index of the value in valueList containing the matching partial valueString. Returns 0 if not found.
Toggle case-sensitive searching by passing a boolean through matchCase.
Search for specific valueString occurrence. Also, a negative occurrence number causes backward search from the end of the valueList.
Specify whether to match the partial valueString from the Left, Center (middle), or Right within the value.

NOTICE: This is a recursive function. If you change the function name then also change it in the function code.

Examples:
GetValueIndexByPosition ("Alpha¶Bravo¶Charlie¶Echo", "charl", False, 1, "L") = 3
GetValueIndexByPosition ("Alpha¶Bravo¶Charlie¶Echo", "charlie", True, 1, "L") = 0
GetValueIndexByPosition ("Daniel¶Danny¶Bill¶daniel¶Frank¶daniel¶Ed", "aniel", True, -2, "R") = 4
GetValueIndexByPosition ("Daniel¶Danny¶Bill¶daniel¶Frank¶daniel¶Ed", "an", False, -2, "C") = 5

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

5 most recent comments | Show all 7 comments

FIXED THE CODE ==========

No more errors with sequential duplicate values, and no errors when calling an occurrence that doesn't exist. Modify the custom function this way:

1) Under the variable line for "vtext", add the following "exist" variable:

// Determine if requested occurrence even exists in list.
exist = GetAsBoolean ( Position ( vlist ; vtext ; 1 ; Abs ( occurrence ) ) );


2) Then replace the "index2" variable with the following Case statement:

index2 = Case (

// IF
exist = 0;

// THEN
0;

// IF
( just = "L" or just = "C" ) and ( Sign ( occurrence ) = 1 );

// THEN
If ( occurrence ≠ 0; GetValueIndexByPosition ( vlist ; valueString ; matchCase ; occurrence; just ) - 1; 0 );

// ELSE
If ( occurrence ≠ 0; GetValueIndexByPosition ( vlist ; valueString ; matchCase ; occurrence; just ); 0 )

);

John Davis, Houston
June 30, 2015 3:19pm

Sorry, I'm still finding errors with my patchwork code above. The Custom Function needs to be rewritten. The original code fails in certain situations where there are double entries in succession. My code above fixes some of that but then breaks other searches/combinations.

John Davis, Houston
July 01, 2015 5:21am

Fixed. Sorry for the delay.

For those with original version and the following changes were made to the code.

Changed:
//index = If ( pos ; ValueCount ( Left ( vlist ; pos ) ) ; 0 ) ;
To:
index = If ( pos ; PatternCount ( Left ( vlist ; pos - 1 ) , "¶" ) ; 0 ) ;

Changed:
//vlist = Case ( occurrence < 0 ; Left ( valueList ; pos - 1 ) ; occurrence > 0 ; Right ( valueList ; Length ( valueList ) - ( pos + Length ( valueString ) ) ) ; "" ) ;
To:
vlist = Case ( occurrence < 0 ; Left ( valueList ; pos - 1 ) ; occurrence > 0 ; Right ( valueList ; Length ( valueList ) - ( ( pos - 1 ) + Length ( valueString ) ) ) ; "" ) ;

Changed:
//index = Case ( occurrence < 0 ; index2 ; occurrence > 0 ; If ( index2 = 0 ; 0 ; index + index2 ) ; index ) ] ;
To:
index = Case ( occurrence < 0 ; index2 ; occurrence > 0 ; If ( index2 = 0 ; 0 ; index + index2 ) ; index ) + If ( occurrence = 0 and index > 0 ; 1 ; 0 ) ] ;

Thanks.

Lewis Lorenz, Tulsa
August 19, 2016 12:52pm

Hey, when the matching value is first in the value list, this CF is returning 0. I think it should be returning 1.

Joshua Willing Halpern, Los Angeles
October 31, 2016 5:03pm

Fixed. Function returns 1 instead zero for matching first value.

Lewis Lorenz, Tulsa
November 24, 2016 1:08pm

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 2 + 9 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. NumberToHexadecimal(NumberValue)
  (Fri, Dec 08, 8:54am)
2. Get_BaseTable
  (Thu, Dec 07, 4:27pm)
3. JSONCreateVarsFromKeys ( json ; namespace )
  (Wed, Dec 06, 8:21pm)
4. GetTableNzme ( field )
  (Tue, Dec 05, 9:16pm)
5. TimeFormatAsText ( theTime )
  (Mon, Nov 13, 1:59pm)
6. ParseWebValueList( text )
  (Thu, Nov 02, 9:52am)
7. SVG_HTML_to_Text ( _svg_text ; _orig_text ;
  (Wed, Oct 25, 4:17am)
8. decFromHex ( hexValue )
  (Mon, Oct 16, 12:34pm)

RSS Feed of Custom Functions