Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Getting Repetitions for a Loop

Featured Replies

I'm used to coding in PHP (and maybe that is the issue here), but when I attempt to setup a loop based on the number of repetitions in a variable in FileMaker, it always seems to get fowled up. Let me explain:

Let's say there are three records in a table called tasks


Go to Record [First]

Loop

  Set Variable [$i; Value:$i + 1]

  Set Variable [$taskid[$i]; Value:Tasks::Task ID]

  Go to Record [Next; Exit after Last]

End Loop



 

Now, in my brain, there should be three elements in an array-like variable called $taskid numbered 1 through 3, a total of three elements.  Then try to use the variable later in the code to establish another loop:

 



Exit Loop If [$i = Count ( $taskid )]

I have the data viewer open to the right of the script and notice the value of Count($taskid) is "?".

Looking over the count function, but all accounts that I am reading, it should be returning 3. What am I doing wrong?

Alas, you are right about that: when speaking about variables (as opposed to repeating fields) the "repetitions" do not add up to an array that could be addressed as such.

  • Author

Alas, you are right about that: when speaking about variables (as opposed to repeating fields) the "repetitions" do not add up to an array that could be addressed as such.

Ok then, it is possible to use variables as arrays?

That's a rather wide question... :laugh2:

In your example, you could have done:

Go to Record [ First ]

Loop

  Set Variable [ $taskid; Value: List ( $taskid ; Tasks::TaskID ) ]

  Go to Record [ Next; Exit after Last ]

End Loop


 

Then, in the other loop:

 


Exit Loop If [ $j > ValueCount ( $taskid ) ]


 

 

Alternatively, you could have kept $i as the count of the first "array" (assuming it's not sparse), or devise another test, for example:

 


Exit Loop If [ IsEmpty ( $taskid[$j] ) ]

  • Author

Alternatively, you could have kept $i as the count of the first "array" (assuming it's not sparse), or devise another test, for example:

Exit Loop If [ IsEmpty ( $taskid[$j] ) ]

That line is slick, I may use that then.

*EDIT*

Worked, I will be using this logic in the future, many thanks!

If it is sparse, you can increment $j in your loop and exit when $j = $i.

If it is sparse, you can increment $j in your loop and exit when $j = $i.

I am not sure I get your point: if the first array is sparse, then $i does not represent Count ( array ).

OTOH, we don't know what the second loop does.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.