Brian Dunning's FileMaker Custom Functions

ValueListSelectedIndex ( File ; ValueList ; Value )

Returns the number of the selected value in a list

  Average rating: 4.1 (31 votes) Log in to vote

Rob Poelking   Rob Poelking - Show more from this author
Kiza Solutions
https://kizasolutions.com

Share on Facebook Share on Twitter

  Sample input:
ValueListSelectedIndex ( "" ; "MyValueList" ; myField )
  Sample output:
6 when myField has selected the 6th value from a value list.

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

Data type returned: Number

Given a list of paragraph separated values, this returns the number of the item selected by a user. If a user selects the third value in a list, then the function returns 3.

 

Comments

DS   DS, NYC
Feb 24, 2009
Doesn't work
 
Nick Stockbridge   Nick Stockbridge, Transmedia Communications Ltd
Oct 26, 2009
Looks as though the author left a reference to a fixed value during testing i.e.

ValueList = "type";
Value = inventory::inv_1004_item_type_t;

If you remove these, it works.
 
Rob Poelking   Rob Poelking, Kiza Solutions
Apr 20, 2010
My apologies, I've updated the function taking out the testing code.
 
ron   ron, bellingham, wa
Mar 23, 2012
For reasons not apparent, if I enter a field value not in the Value List, I usually get 0 but sometimes I get 1. Huh?
 
Rob Poelking   Rob Poelking, Kiza Solutions
Mar 24, 2012
Without seeing your code maybe check for the existence of a carriage return. I use this function and variations of it often.
 
Mike Scott   Mike Scott, Liverpool, UK
Nov 15, 2012
Works a treat - thanks
 
Sel   Sel, Bellevue, WA
Jun 8, 2013
Hi All:

Firstly Rob thanks for posting.

I am new for FM coming from 4D.

I want to find the list item chosen (row, element number) so I think this is what I need.

I created the Function by coping it (Manage ->Custom Functions).
When I do that I am prompted to enter Parameters for "file", "ValueList" and 'Value" (note in the code there is "file" and "File". (?same).
So if I enter "file", "ValueList" and 'Value" as the parameters I can save the Function.

Now, how do I use it/connect it to the process of selecting a list item, to get the list item number chosen from a list, name "Color".

You have the first parameter (file) in the function as "" (null string) and the Value field will be where I will store the result.
I dont see a way to assign the file parameter from the File list (you can only assign Fields).

Would really appreciated a bit more details on how to assign the parameters correctly and hook this function to the choosing of the list.

Thanks again

Sel
 
Rob Poelking   Rob Poelking, Kiza Solutions
Jun 10, 2013
Hi Sel,

I will try to answer you briefly because I don't want to abuse Brian's tool here.

First, the parameter "file" is optional. If you do not assign it, then the function will assume that the value list you are trying to reference is located within the working file. Adding this parameter allows you to reference a value list in a different FileMaker file. If you want to specify the file, then simply quote it as a string constant [ ValueListSelectedIndex ( "my_file.fp7" ; "MyValueList" ; myField )].

Next, let me again point out that what this function returns is an index value for a selected item. If you assign a field with a value list of "Fruit Options" and "Fruit Options" is a list of fruits, if a user selects "Pineapple" in that field and "Pineapple" is the 5th item in that list, this function returns 5.

And as to the use of "file" and "File", yes, they are the same. FileMaker is not case sensitive in functions.

If you need more help, you can track me down from one of the sales guys at Excelisys by going to our web site.

I have some additional functions based around this one as well that allow you to build a custom list on the fly, or reverse the process and select an item from a list passing in the index value.
 
Rich   Rich, UK
Feb 6, 2014
Hi, I must admit I'm really not that familiar with Filemaker, but I've taken over a club student records database for a martial arts club, where each student has their belt 'grade' in a field which is usually entered via a drop-down from a value list.

There is an existing script which scans through the student records and updates any selected records with the date of their last exam. What I need to do is to have their grades automatically update to the next value in the list. Would really appreciate any pointers on how I could do that!
 
Rob Poelking   Rob Poelking, Kiza Solutions
Feb 6, 2014
Rich,

Shoot me an email direct - rob@excelisys.com
 
Uuree G   Uuree G, Japan
Jun 28, 2018
Not accurate for all cases if value contains 24 and 424. So need to make it unique to avoid that one value is part of another.

For example, putting special marks at both sides become: ~24¶, ~424¶

Suggestion:

Let
(
[
file = if ( isempty ( file ) ; get ( filename ) ; file ) ;
items = ValueListItems ( File ; ValueList ) ;
items = Substitute ( items ; "¶" ; "¶~" ) ;
Value = "~" & Value & "¶" ;
items = If ( Right (items ; 1 ) <> "¶" ; items & "¶" ; items )
];
PatternCount (
Left (
items ;
Position ( items ; Value ; 1; 1 ) + Length ( Value )
) ; "¶"
)
)
 
Uuree G   Uuree G, Japan
Jun 28, 2018
Forgot putting Initiator at beginning

items = If ( Left (items ; 1 ) <> "~" ; "~" & items ; items )
 

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: