Use a layout with global fields for the users to enter their search criteria. Include fields for lenght, width, units and error factor.
Your script can then use the inputted data to convert non millimeter dimensions into millimeters and use the error factor to compute minimum and maximum dimensions in order to produce and enter the find criteria needed.
Let's use auto-enter calculations on global fields to do the units conversion. I'm only going to use length in this example, but you should be able to extend the method to specify a width as well.
You'd have a global field, gLength for the user to input the length, gUnits so they can select units from a value list and gError to add an error range. gConvFact can then use this auto-enter calculation:
Case ( gUnits = "mm" ; 1 ;
gUnits = "Inches" ; 2.54 ; //converts inches into millimeters
// add as many terms as you need for all other units you choose to use in your conversion calcs
Now a script can perform your find:
Enter Find Mode 
Set Field [YourTable::Length ; Let ( [L = gLength * gConvFact ; E = gError * gConvFact ] ; L - E & "..." L + E ) ]
Set Error Capture [on] // suppresses "not found" error dialog if no records match
...ummm, I forgot to add the part where I say "I just started using FMP about a month ago, so I am totally new to this", lol. I did however update my tagline with the appropriate info and will add this to any further questions I post. My apologies for not specifying that earlier.
When entering the following calculation:
Let ( [L = Phone Table::Length * Phone Table::Conversion Factor ; E = Phone Table::Error Factor * Phone Table::Conversion Factor ] ; L - E & "..." L + E ) ]
into the script, I get the following error:
An operator (e.g. +, -, *, ...) is expected here.
I click OK, and the last letter "L" in the calculation is highlighted (the one in L + E)
I left out an operator, &
Let ( [L = Coin Table::Length * Coin Table::Conversion Factor ;
E = Coin Table::Error Factor * Coin Table::Conversion Factor ] ;
L - E & "..." & L + E ) ]
lol, awesome man.... this is awesome. PhilMod, you are my new best friend!
lol, now Im getting the same error but it is highlighting the last bracket in the calculation.
L - E & "..." & L + E ) ]
nevermind, deleted the last bracket...
Yeah, that bracket isn't part of the expression. It's supplied by the script editor after you dismiss the specify calculation dialog.
I am sorry for being such a pain in the rear....
I added the additional fields to the table in question:
- Error Factor
- Type: Number
- Conversion Factor
- Type: Calculation
- Options/Comments: Case ( Units = "mm" ; 1 ; Units = "cm" ; 10 ; Units = "m" ; 100 ; Units = "in" ; 25.4 ; Units = "ft" ; 304.8 ; Units = "yd" ; 914.4 ; )
- Type: Text
- By Value List
I added a "Custom Values" list for the "Units" field and populated it with "mm, cm, m, -, in, ft, yd".
I also added the following script to be executed when the "Search" button is pressed:
- Enter Find Mode 
- Set Field [Phone Table::Length; Let ( [L = Phone Table::Length * Phone Table::Conversion Factor ; E = Phone Table::Error Factor * Phone Table::Conversion Factor ] ; L - E & "..." & L + E )
- Set Error Capture [On]
- Perform Find 
Lastly I added the a dropdown list for the "Units" field and a text box for the "Error Factor" field to the Search Layout.
I tried running a search without entering anything into the "Units" and "Error Factor", and it worked fine.... if I entered 56, it returned all results in the database with a value of 56 in the length. I tried another seach entering 56 in the length and selecting mm in the "Units" dropdown list, I got the "No records match this find criteria" message. Same thing if I entered 56, selected mm, and added an "Error Factor" of 5.
I went back to the main table and populated a couple of the "Units" fields with "mm" as a value and tried searching again. If I enter 56 in the length and select mm as the units it only returns the items that have the "Units" field populated with a "mm" value. None of the items that have blank values for the "Units" field are returned in the results.
When trying to add 2.20472441 as a length value and selecting "in" in the "Units" field = "No records found" message.
Adding ANY value to the "Error Factor" text box will always return a "No records found" message no matter what the other values are.
Is your length field a number or a text field? It must be a number field for this to work. (If you need to show units, either put the units in a separate text field or use data formatting via the Inspector to add it as part of the fields display settings.)
The length field is a number field. The units do not need to be shown, but I have added a separate text field for them and populated them with custom values (mm, cm, m, -, in, ft, yd)
Immediately after running the script. Select Modify Last Find. This takes you into find mode and displays the crtieria used to perform the most recent find. Check the criteria in the Length field and see if it is correctly entered.
I did this and the same values I entered are still there.
But what values do you see. I'm looking to see if the criteria has the correct format.
If you enter 22 mm +/- 1, do you see this criteria in the length field?
or do you see something else?