We help IT Professionals succeed at work.

Looping through a field using wordcount function in Filemaker Pro 11

PachecoPrimo used Ask the Experts™
I have a database (see attached) with one table 'Main'. There is a field called 'Wordcount_ItemDetails' which is a calculated field that uses the function 'WordCount' to count the number of words found in the field 'Item_Details'. What I am trying to accomplish is to create a script that lets me loop through the 'Item_Details' field contents (words) based on the numberof words found in it. This is to be done for each record.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Will LovingPresident, Dedication Technologies, Inc.

Pacheco - what you don't say is what you want to do on each loop through. What does the WordCount() function have to do with the loop? What operation do you want to perform that is related to either of these fields?

For reference, a basic loop script looks like this:

Go To Record [ First ]
    Some function or scripts steps based on Word Count?
    Go To Record [ Next ; Exit After Last ]
End Loop

It might also first include a Perform Find [ ] or Go To Related Records [ ] function to find a particular set of records.


I want to select each individual word and do a  perform find.
President, Dedication Technologies, Inc.
Perform a Find where? Are you performing the Find on the same fields, on another fields, are you opening a new window to the same table, a different table? Please be more specific...

To at least address the question of performing a Find using each word in the table, I'm assuming what you want to know is how to select each word. The loop - which would be two loops, on for going from record to record and one for going from word to word within the record - might look something like this:

Go To Record/Request/Page [ First ]



    Set Variable [ $WordNumber ; $WordNumber + 1 ]
    Exit Loop If [ $WordNumber > WordCount( Main::Item_Details )

    Set Variable [ $Word ;  MiddleWords( Item_Details ; $WordCount ; 1  ) ]
    Perform Find [ Restore ]
    Etc., Etc. Etc.

    Exit Loop

    Go To Record [ Next ; Exit After Last ]
    Set Variable [ $WordNumber ; "" ]  

End Loop

The attached file has a version of this script which presents a dialog rather than performs a Find (since I don't know where or how you want to perform the Find.

A couple of notes:

1) You don't actually need to have a separate field to calculate the WordCount() function since it's now being done in the script.

2) The $Word script variable contains the word you want to perform the Find on and you can use that in your save "Perform Find [ Restore ]" step if you are using FileMaker 11 or 12 but I'm pretty sure you can't use script variables in a saved Find before FM 11. In that case you would simply need to use:

   Enter Find Mode [ ]
   Set Field [ Item_Details ; $Word ]
   Perform Find [ ]