FileMaker脚本中的迭代循环等效?

时间:2014-04-06 04:39:50

标签: database scripting filemaker

我是FileMaker Pro脚本的新手,我想知道它是否等同于迭代循环。 (即类似于C / C ++ / Java中的循环)。如果是这样,任何人都有任何我可以看到的例子。 (如果有帮助,我会使用FMP 11。)

算法:我目前有一个数据库,我希望迭代数据库中的所有记录,并检查每个记录中的两个特定列,如果它们包含特定的数字,然后递增一个计数器。然后转到下一条记录。

谢谢!

1 个答案:

答案 0 :(得分:1)

FileMaker脚本中的基本循环结构如下所示:

# 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

但是,查询所有数据通常是一种非常慢的方法。有许多方法可能更合适。举个例子,假设你在数据中寻找静态值,你可能会这样做:

# 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 ) ]