Write your own progress bar with FileMaker Pro 9

Progress bar


Sometimes a script running within your FileMaker solution may take a while to complete. A user-friendly application should provide some indication to the user that the script is running. Progress bars are a commonly used interface element to convey how far along a script is.
This article will explain how you can easily implement a progress bar in your solution.

Step 1. Determine the completion status of your script.

The completion of a script can be represented by a percentage. In FileMaker there are some functions that can be used to determine the completion of a script.
If you for instance want to loop through all your records, you can use the Get(FoundCount) and the Get(RecordNumber) to calculate the completion.

Let
(
[
thecurrentStep = Get(RecordNumber)
;
theTotalNumberOfSteps = Get(FoundCount)
;
theCompletion = Truncate ( (thecurrentStep/theTotalNumberOfSteps) * 100 ; 0)
]
;
theCompletion
)


If your table has 300 records and you are currently on record 100, the formula will return 33. This means you have already accomplished 33 % of your script. The truncate function is used to be sure the formula will return an integer.

Step 2. Drawing a progress bar

In the next step, we will create the progress bar.

- Go to "Manage > Database" and create a new text field "progress bar".
- Select the field and choose "Options...".
- Click on the tab "Storage"
- Make the field global and fill in the number of maximum of repetitions: 100

Now we have a repeating field with 100 repetitions. Every repetition will represent one percentage of the progress of the script.

Add the field to your layout and be sure all 100 repetitions are on the layout.

100 repetitions


Step 3. Make the progress bar working
If your table has 300 records and you are currently on record 100, the first 33 repetitions must be blue.
To establish this we will make use of the new conditional formatting feature in FileMaker 9.

Conditional Formatting

- Go to layout mode and select the "progressbar" field.
- Right-click and choose "Conditional Formatting"
- Click on the "Add" button
- Choose "Formula is" in the condition value list and click on "Specify ..."

Add the following formula:

Let
(
[
thecurrentStep = Get(RecordNumber)
;
theTotalNumberOfSteps = Get(FoundCount)
;
theCompletion = Truncate ( (thecurrentStep/theTotalNumberOfSteps) * 100 ; 0)
]
;
theCompletion ≥ Get ( CalculationRepetitionNumber )
)

The function "Get(CalculationRepetitionNumber)" will return the number of the current repetition.
For repetition 1, the result of the calculation will be true.
For repetition 33, the result of the calculation will be true.
But for repetition 34 or higher, the result of the calculation will be false.

The only thing you have to do now, is to choose the fill color and you are finished.

Download the example file

Leave a Reply

You must be logged in to post a comment.