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.

Interating through all results of a found set

Featured Replies

  • Newbies

Hi there. I am new to FileMaker and I had a quick question. I have a program that I'm modifying. I have a set of results and need to go through them one by one, and use two of the fields to determine if it is within a range.

Particularly, I'm using coordinates to determine whether a point is within a given wedge (the wedge has a direction and an angle of inclusion).

I have the math to do it, but I need to know how to iterate through the results and grab two of the fields. Let me know if you can help.

Thank you

Eamon

Edited by Guest

You might want to use a script:

Freeze window

Go to record( First )

Loop

If( your math here )

Set field( InRange, "Yep" )

End If

Go to record( Next, exit after last )

End Loop

Or, you could use a calculated Replace command.

Or, perhaps you could just define a calculated field.

You might be able to use a multi criteria > and < relationship to do this as well.

We would need to know the math to give more detail.

It would probably look something like:

gHighXRange>=XCoordinate

gLowXRange<=xCoordinate

gHighYRange>=YCoordinate

gLowYRange<=yCoordinate

Where the left fields are global fields that you would enter the appropriate boundaries in.

*This would apply to all records, not just the found set, so you would need to account for that by adding a fifth (or sixth or seventh) criteria to the relationship that would filter the records to match what was your found set.

Edited by Guest
found set caveat

  • Author
  • Newbies

I'm going to write an atan2 function that will return the angle in radians of the point relative to a specified center point. Then I'm just going to check if it is within the specified angle range.

Pretty simple. The atan2 function will be harder than anything else, and even that will be easy.

How can I get the value of two fields of the record I'm working with?

Thanks

Eamon

It has been a while since my last inverse trig class, but:

For the relationship approach, you would put your atan2 function as an unstored calc field in your table. Then create 2 global number fields:

gArctangentHigh

gArctangentLow

Your relationship would have:

gArctangentHigh>=atan2

gArctangentLow<=atan2

If you place a portal on your layout that displays records from your new table occurence and type the numerical equivalent of −π/2 in gArctangentLow and π/2 in gArctangentHigh (and if I get how atan2 works), then you should see all records. You could adjust the high and low to narrow the range.

You could have the globals be unstored calculations if you wanted to have a more precise approximation of π/2.

How can I get the value of two fields of the record I'm working with?

It depends what you're doing. If you go to Define Fields (Define Database in FM8) and make a new calculated field, you'll see the Calculation dialog box. In the upper left is a list of fields; at the upper right a list of functions.

In the context of a script, you might use a Set Field step, or an If, or Go to layout by calculation... there are many contexts where the Calculation dialog is available.

Within that dialog, just select a field from the list or type its name directly.

I am confused by the intended use for these two fields being evaluated. Are you using this as a means of record selection (finding a set of records meeting a criteria), or to derive a new result in another field somewhere?

The answer you desire will be different depending on your desired use.

Tim

  • Author
  • Newbies

I just want to get the contents of two fields and use them in a calculation.

Say I have field A and field B.

I just need to go to the first record, get what is in A and B, and do my calculation.

Then, based on the calculation, I either keep the record or delete it.

Eamon

Ok,

Then I would approach the problem as fitch has above with a script.

pseudo code:

1. perform your find - yield found records

2. freeze window - to avoid flashing

3. set variable [$whateverHigh = 10000]

4. set variable [$whateverLow = 500]

5.go to record/request [first]

6. Loop

set variable [$result = Field_A*Field_B]

if [$result < $whateverLow or $result > $whateverHigh]

omit record (removes from found set) or Delete record (does as the command suggests)

endif

go to record/request [next] exit after last

endloop

7. what is left meets your test.

In step 6 the point of reference is the current record, so just ask for the fields in a formula and you have selected and used the fields from the current record. This loop will execute on each record in the found set until it reaches the last record. As each record is read the if statement will decide it's fate (keep or remove), leaving only those passing the test. If you wish to see the process, then omit the freeze window step and you can add the pause script step if you wish to interact with the records as the script progresses.

Hope this helps,

Tim

  • Author
  • Newbies

code-1.jpg

Click the link for a larger image.

Here's a code snippet of what I'm trying to do. I thought I had it right but the idea is that in the database, you can set a wedge direction and angle to include certain data points, and no matter what angle I set, the same points are always included. Any idea why this would occur?

Thanks for the help too, I think I'm getting close.

Eamon

Edited by Guest

  • Author
  • Newbies

OK, disregard previous post.

I finally figured out how to do some error checking and fixed a bunch of things. However, I have the program set the "include" field to 0 for all records and then 1 if the record should be included. Then, I say

Go to Record[First]

Loop

If include = 0

Delete Record

End If

Go To Record[ Exit after last, Next ]

End Loop

However, none of the records are getting deleted. What's the deal with that?

Eamon

Couple of questions.

Is point_angle a global of the same type (numb, text, etc)as the result in your calculation (if statement)?

Does the first record truly pass the test?

Have you tested the value of point_angle returned from the subscript?

Before you call the subscript, clear the point_angle field. It could be keeping a good value. Put a pause in your master script to show you the value of point_angle, say right after the main script resumes.

I can't say why none of the records are getting deleted. But for sure you should change that script to this:

Go to Record[First]

Loop

If include = 0

Delete Record

ELSE

Go To Record[ Exit after last, Next ]

End If

End Loop

Otherwise, if you have two records in a row where include=0, the second one won't get deleted. This is a common beginner scripting mistake.

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.