Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 4781 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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?

Posted

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.

Posted

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?

Posted

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

Posted

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!

Posted

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.

This topic is 4781 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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