Bigun Posted October 20, 2011 Posted October 20, 2011 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?
comment Posted October 20, 2011 Posted October 20, 2011 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.
Bigun Posted October 20, 2011 Author Posted October 20, 2011 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?
comment Posted October 20, 2011 Posted October 20, 2011 That's a rather wide question... 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] ) ]
Bigun Posted October 21, 2011 Author Posted October 21, 2011 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!
David Jondreau Posted October 22, 2011 Posted October 22, 2011 If it is sparse, you can increment $j in your loop and exit when $j = $i.
comment Posted October 22, 2011 Posted October 22, 2011 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.
Recommended Posts
This topic is 4800 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 accountSign in
Already have an account? Sign in here.
Sign In Now