1 of 1 people found this helpful
Greetings, and welcome to FileMaker scripting. Short answer: Yes. And this is not limited to scripting, but utilizes functions that may be part of calculated fields as well.
So, for starters, you can take your multi-line value (in a text field or variable) and snag a whole desired line:
Let's say AddressField contains
100 Main Street
Worcester, MA 02743
setting $csz = Getvalue( AddressField; 2 ) would populate the $csz variable with the City, State and ZIP Code line.
setting $zip = rightwords( $csz; 1 ) would populate $zip with the ZIP Code.
setting $state = middlewords( $csz; 2; 1 ) would populate $state with "MA"
Within a calculation or script step, this could all be done in one, compound formula.
This is a very simplistic example, and would fail if the data wasn't accurately predictable, such as if the City, State, ZIP line was not the 2nd in the block of text, if the ZIP Code was missing or if the town name had more than two words. Thus, techniques for detecting or controlling the content must be devised. But I think this answers your basic question.
You csn also research the "values" functions as they can be useful.
but please note that all of these return text with a return as the last character--which can cause annoying calculations.
In addition, you can websearch for filemaker custom functions to find web sites where you can get custom text parsing functions if you use FileMaker Advanced.
There are quite a few Text functions:
characters? Left, Middle & Right
words? LeftWords, MiddleWords, RightWords & WordCount - of course read up on what a "word" means
lines? LeftValue, MiddleValue, RightValue & ValueCount - returns are the the delimiter in a "value list"
Then there are: PatternCount, Position & Length that can be used with the above.
You can get a PDF of all the functions:
A little different, but there are so many things that can be done to extract/parse text. The functions can be nested. And the Let() function is often used to setup temporary variable to 'chunk' the text and parse chunks. In addition scripted loops can use $variables to help chunk the text and parse.
Follow Bevs advice.
The text and list functions are a foundation piece of knowledge with ANY programming tool.
Invest the time.
Play with ALL of the functions.
Learn the word delimiters.
1 of 1 people found this helpful
And just to add, learn to use the Let ( ) function; it is without doubt—in my mind at least—THE best way to construct a complex calculation.
And almost the ONLY way...
Also, just to point out a picky detail but one that if not addressed can lead to confusion.
While this entire thread is titled "scripts", we are actually discussing calculations. Scripts are something else....
I am assuming that I can add the setting $csz = Getvalue( AddressField; 2 ) as a script line. But I don't find "setting" only some set (like set value). But then I have a problem inputting the variable name. I realize that once I get into the filemaker form this will become easy (programming since 1963, Fortran in 68 & using basic and hypercard since). The problem is getting the quirks.
In addition to the sound advice you've already received, I can only add that if you are inputting Address data, then it is simpler to enter that data into separate fields for street, city, zip and country, rather than input the block into one field, then extract the various elements.
Concatenating the fields to make an address label, is generally easier than parsing, especially if an address format does not always conform to your expectations.
Excellent suggestion, John! Sometime the data we get is the data we get. Parsing from there is all we can do.
We actually haven't given you a single script line. We've only shown examples of calculations, not scripts. These calculations can be part of a script step, but aren't actual script steps themselves. If you want to set the variable $csz to a value, you might use this in a script:
Set Variable [$csz ; value: GetValue ( AddressField ; 2 ) ]
Note that the example provided earlier is a calculation that becomes a parameter of the Set Variable script step that you might create in the scripts workspace.