Do you mean sentence or carriage return single line or paragraph when you say line? You can look for the carriage return and place your cursor at the begining of the first carriage return with:
Set Selection [ start ... Position ( table::field ; ¶ ; 1 ; 1 ) ] ... there is no need to enter an End value at all.
If by line you mean paragraph then look for the second carriage return (read up on Position function in FM Help). :-)
And if you mean sentence then you will need to look for the period instead. However, as you know, periods can exist within sentences just as well so it would not be dependable.
Is each line ended a return?
If not, there is no way in FileMaker to predict which character will start the a new line when the text "wraps" to the next line.
If each line ends with a return, you can use the position function to find the return character preceding the start of the next line and determine your selection range from that point.
Ok this is how I have it...
A Text field containing almost identical beginnings, but differ a bit in leanght on the first line/paragraph/sentence!
If the first line in the text field ends with a period does that make it to a sentence? If so can I by adding a Period where it is missing one make use of a calculation that jumps to a first position after that Period?
Is a Enter command from the Keyboard represented as a paragraph? That makes the text "jump down one "line" in the text field.
So I have a text field where I would like to jump to line two, or paragraph two. and then be able to use "Set Selection" to pick out a spesific number of characters/words in that paragraph!
The "Set Selection" command I understand, even though I didn't know that you could jump over the end posistion, so thanks for that, that is very useful :)
Is this more clear?
Andreas said, "So I have a text field where I would like to jump to line two, or paragraph two. and then be able to use "Set Selection" to pick out a spesific number of characters/words in that paragraph"
Why are you picking out specific characters/words in that paragraph? Please explain what you are trying to do. A script probably isn't what you need at all so the purpose and context is important to know.
Oh, I thought I was clear there,
but I try again,
I have a text field in the layout, where I have different parts that I would like to copy to other fields. I have this old text field that is a mix of "values" imported from an outside source (other, older database). From start the information in this text field wasn't very important, just good to have - just in case :)
Now I would like to pick out different parts of that text and put in these other fields or tables! I have already managed to copy the first line and seperate the different "parts" of that line using "Set Selection" - but I am a bust on going to the other lines without manually deleting the first line, therefor making the second line the first line, then running a second calculation that does it's work and so on... but that seems a bit to cumbersome a way to do it, so...
The text field looks like this:
01x01 - Episode Title
First aired: MMM/DD/YYYY
Writer: FirstName LastName
Director: FirstName LastName
Guest star: Actor Name (Character), Actor Name (Character), ... Actor Name (Character)
I would like to be able to "script" or automate a calculation that goes through all the posts copying, or moving, the different parts in the text field like this:
Step 1: Copy text "01x01" to field Prefix
Step 2: Copy text "Episode Title" to field Episode Title
Step 3: Copy the date after text "First aired:" to field Air Date
Step 4: Copy name after text "Writer:" to field Writer
Step 5: Copy name after text "Director:" to field Director
Step 6: Copy names and charachters in this part to text field Guest star
Step 6: Copy text, containg the plot, that comes after last "Guest star" to field Plot
I hope that this is a bit clearer!
The help I need is to understand the paragraphs, or sentences, or lines in this text field. How to pick out line two and position 14, how to pick out line 3 and position 9 and so on...
Set selection and copy/paste are not needed here.
Note: the ¶ in LaRetta's example is the FileMaker operator for the carriage Return character. In word processors, this character often marks the beginning of a paragraph.
Here a few sample calculations that extract the text you need:
To extract the prefix: Leftwords [YourOldTable::TextField
The title: Trim ( Right ( YourOldTable::TextField ; Length ( YourOldTable::TextField ) ; Position ( YourOldTable::TextField ; "-" ; 1 ; 1 ) + 1 ) ) )
First Aired: GetAsDate ( RightWords ( GetValue ( YourOldtable::textField ; 2 ) ; 1 ) )
These can be used with Set Variable to load variables with values so that your script can switch to a layout based on the appropriate table, create a new records and then use Set Field to copy the data from the variable to the field in the new record.
Getvalue lets you refer to a specific line in the field.
Position, let's you find the position of a key group of text.
Leftwords, Rightwords, Middlewords let you refer to a specific word or words in the text.
Left, Right, Middle, let you refer to a specific group of characters in the text.
Ok, so that's clears up a bit of my lack of knowledge :)
I will try these commands and see how it goes
I'll post an comment when I am done
Ahh, one-time conversion. Here's how I would approach this task:
Create each of your new fields as calculations first (Prefix, WriterFirstName, WriterLastName etc). When you have reviewed the resulting calculations and have them all so they split properly, simply change each calc to standard field (be sure to select the correct data type). When you exit field definitions then the data will plant into the fields and you are done.
Let's call this field TEXT and back up first.
It is easiest if you use Let() for your calculations. It keeps the thinking clearer. So for instance, to get the "FirstName LastName" of a Writer, it would be:
Let ( [
line = GetValue ( text ; 3 ) ;
separator = ":" ;
start = Position ( line ; separator ; 1 ; 1 ) + 1 ;
end = Length ( line ) - start + 1
LeftWords ( Middle ( line ; start ; end ); 1 )
You can copy this calc and use it, just by changing the line from 3 to whatever line you wish and changing the separator from : to -. So to get the Writer FirstName ONLY from this calc, you would wrap the portion in blue as indicated in red. You will need to be careful with the names because, what if the person has two first names such as Mary Lou Smith; calc can't tell difference between this and John Van Halen, for example.
So create each of your resulting field calcs and then post if anything isn't exactly how you want it. :^)
ADDED: Also, you may need to wrap the resulting calc in Trim() if you notice leading or trailing spaces. You won't need to use Trim() if you use xWords because LeftWords() etc drops leading and trailing word-break characters such as space.
I feel I need to mention one more thing ... you have several 'people' associated with this Title. In truth, all of the people should be in a related table to Titles maybe called Cast, related on the TitleID. Then you would have a field for Role which would hold Writer, Director, Guest Star etc. and each record in Cast would hold one of these parsed values.
In this way, you do not need fields for Writer FirstName, Writer LastName etc. In my prior posts, I was focusing on producing each individual piece that you need. We can then take this information and turn them into related records. We can help you with it if need be. You probably already have this but I wanted to mention it.
Thanks for that answer. Together what Phil explained I will start to work on this after work (it's Friday morning here). The layout for now only has a regular text field for each part, but the idea is to have different tables with proper relations instead.
The Writer and Director fields can ofcourse hold multiple names in some posts! So we also need to take that into the calc.
I have one question though? What is the differens between a script and a calculation? I mean, some advise I get is to use a calculation and not a script. But isn't that the same thing, or atleast a script is built up by different steps, a calculation being on those steps!
Anyway, thanks again for your help on this. I think that I finally are getting some where with this :)
"What is the differens between a script and a calculation? ... a script is built up by different steps, a calculation being on those steps!"
A script is a macro (or recorded group of actions). One action called Set Field takes the parsing calculation and places the resulting data in the field. Scripts are created up in Scripts section and may include many things such as switching layouts, printing, looping through records, etc.
A calculation is a dynamic display of only that calculation result for each record and is defined in field definitions. The reason I suggested creating calculations of each of them is simplicity ... you can immediately see the results of your calculation (instead of waiting for script to *run through records) AND then just convert the calculations over to data when they are correct.
Changing a calculation to data field is also faster than looping through records or using Replace Field Contents.
I have managed to get the first parts of this solved! (waiting with the writer, director and guest star till later)
First the scripts copy the title prefixes and paste them into two seperate fields, Season# and Episode#, after that the Title is copied to the Title field, this time I am copying all words of the Title and only from the first line.
Second I copy the airdate to the field Episode Airdate. And now I have more controll over the statistics here...
And last I copy the plot text to it's own field.
The whole thing was actually really easy :)
Thanks to both LaRetta and Phil for your awesome help.
Have a nice weekend