0

I'm new to FileMaker Pro scripts and I'm wondering if there's an equivalent to an iterative loop. (i.e. like for loop in C/C++/Java). If so anyone have any examples I could look at. (I'm using FMP 11 if that helps).

Algorithm: I currently have a database where I'm looking to iterate through all the records in the database and check two specific columns in each record and if they contain a specific number and then increment a counter. Then move to the next record.

thanks!

1
  • "check two specific columns in each record and if they contain a specific number" Couldn't you find these records to begin with? Finding is (in most cases) fast. Looping is not. Commented Apr 6, 2014 at 8:29

1 Answer 1

2

A basic loop structure in a FileMaker script would look like this:

# Start with a found set of the records you want to investigate (or all records)
#
# Set the counter variable
#
Set Variable [$counter ; Value:0]
#
# Go to the first record
#
Go to Record/Request/Page [First]
#
# Loop until you reach the last record, incrementing counter if appropriate
#
Loop
   If [ table::value = desiredValue ]
      Set Variable [$counter ; Value:$counter + 1]
   End If
   Go to Record/Request/Page [Next ; Exit after last]
End Loop

However, this is usually a pretty slow method to query all of your data. There are a number of ways that may be more appropriate. Taking your example, and assuming you are looking for static values in your data, you might do something like this:

# Assume we are looking for field1 = value1 and field2 = value2
# 
Enter Find Mode []
Set Field [ Table::field1 ; value1 ]
Set Field [ Table::field2 ; value2 ]
Perform Find []
#
# We have now found all records where field1 = value1 and field2 = value2
# We simply set $counter to the count of found records
#
Set Variable [ $counter ; Value:Get ( FoundCount ) ]
Sign up to request clarification or add additional context in comments.

1 Comment

Great thanks! Makes sense. It's a pretty small database but I want it to be designed where it could be scalable for larger projects. Thanks for documenting it so well too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.