13 Replies Latest reply on May 19, 2017 3:35 PM by beverly

    Add numbered paragraphs


      I am hoping to make a script to add numbers to paragraphs.


      I was wondering if anyone has ran in to this before and would get me headed in the right direction.





        • 1. Re: Add numbered paragraphs

          Are you talking about adding numbers to printed report paragraphs?

          • 2. Re: Add numbered paragraphs

            If I need such an entity to be enumerated (sorting, boilerplate, etc.), then I consider making these into a table (one paragraph per record).


            Sent from miPhone

            1 of 1 people found this helpful
            • 3. Re: Add numbered paragraphs
              edit: Jive didn't like my HTML formatting. Boo!

              If you define a new paragraph as the presence of carriage return then this is relatively straightforward. Here's a potential script snippet:


              Set Variable [ $delim; Value: ". " ] //configure how we want to delimit our paragraph numbers
              Set Variable [ $x; Value: 1 ] //starting count
              Set Variable [ $y; Value: ValueCount ( $myText ) ] //total number of paragraphs
              Set Variable [ $myText; Value: $x & $delim & $myText ] //add number to first paragraph

                  Set Variable [ $x ; Value: $x + 1 ] //increment counter for next paragraph
                  Exit Loop If [ $x > $y ] //exit if counter is greater than number of paragraphs
                  # this next step replaces the "x - 1"th carriage return with a carriage return plus our paragraph number plus our delimiter
                  Set Variable [ $myText; Value: Replace ( $myText; Position ( $myText; "¶"; 1; $x - 1 ); 1; "¶" & $x & $delim ) ]
              End Loop

              • 4. Re: Add numbered paragraphs

                There is an error in your code: line 3 valuecounts line 4, i.e. a variable is used before it's defined. Doesn't work in FM ... (there is no syntax error, but the reference is empty)


                The other problem of course is that $myText is never initialized with any actual contents, i.e. a text field's contents ...


                Apart from that, I think this is easier if you don't treat the first paragraph as something special, and if you take care to only number what should be numbered.


                Set Variable [ $myTextRaw ; YourTable::someField ]

                Set Variable [ $myText ; Substitute ( $myTextRaw ; "" ; "§§§ ) ]

                Set Variable [ $paraCount ; ValueCount ( $myText ) ]

                Set Variable [ $delim ; ". " ]


                  Exit Loop if [ Let ( $i = $i + 1 ; $i > $paraCount ) ]

                  Set Variable [ $thisPara ; $i & $delim & GetValue ( $myText ; $i ) ]

                  Set Variable [ $result ; List ( $result ; $thisPara ) ]

                End Loop

                Set Variable [ $result ; Substitute ( $result ; "§§§" ; ) ]

                Ser Field [ YourTable::resultField ; $result ]

                • 5. Re: Add numbered paragraphs

                  If you want each ¶ to start a new paragraph and are not opposed to using custom functions, then this is easily handled by CustomList().


                  CustomList(1; ValueCount(MyText); "[n] & " & Quote(". ") & " & GetValue( MyText ; [n] )")


                  and MyText = "My first line¶The second line.¶A third line is here."


                  will produce


                  1. My first line

                  2. The second line.

                  3. A third line is here.



                  • 6. Re: Add numbered paragraphs

                    Funny, I got a "The specified table could not be found" error when I tried executing your version.

                    Also, in line two: Set Variable [ $myText ; Substitute ( $myTextRaw ; "" ; "§§§ ) ] I get an error "This text content does not end with a quotation mark." (of course the first one isn't a real error but the second one is a real syntax error)

                    • 7. Re: Add numbered paragraphs

                      If you have include tab characters after the number, it's possible to use paragraph formatting on the Inspector's appearance tab to get numbers as hanging indents with the text properly aligned and wrapped within the field or merge text object.

                      2 of 2 people found this helpful
                      • 8. Re: Add numbered paragraphs

                        user1069 wrote:


                        of course the first one isn't a real error but the second one is a real syntax error)



                        Yes, that stuff happens when you type code from scratch on an iPad, rather than copying it (somehow) from a working script.


                        The first error comes from the fact that there is no field in your file with that fully qualified name, and to correvt the syntax error, just add the missing quote after the pilcrow.


                        I actually did set up a quick and dirty sample file, where that method worked. Thing you have to watch out for and take care of are more than two CRs in succession.

                        • 9. Re: Add numbered paragraphs

                          Here is another way to do it directly in a calculation (without Custom Functions).



                          theText = MyText; // Your text field takes the place of MyText

                          theTextRemEndPilcrow = Case(Right(theText;1) = "¶"; Left(MyText; Length(theText) - 1); theText);

                          theCalc = "Let([$_num = 1]; \"\" ) & " & Substitute(

                             Quote(theTextRemEndPilcrow); "\¶";

                                 "\¶\" & Let([$_num=$_num+1]; $_num & \". \" ) & \""



                          "1. " & Evaluate(theCalc)





                          • 10. Re: Add numbered paragraphs

                            Here is another way using a recursive Custom Function.

                            Note that this lets you specify the format and starting value for the leading number.  It is auto-incremented using SerialIncrement().


                            It is written to have a List as input, but that's what a block of text with ¶ is.  Each paragraph would be an entry in the list.

                            On FileMaker Pro this should work with text containing up to 10,000 paragraphs.


                            /*  NumberTheList(text; firstEnumeration)


                            Example: NumberTheList("Dog¶Cat¶Pig"; "1. ")


                            1. Dog

                            2. Cat

                            3. Pig

                            Example: NumberTheList("Dog¶Cat¶Pig"; "001. ")


                            001. Dog

                            002. Cat

                            003. Pig


                            Specify the value for firstEnumeration to designate the format and spacing of the leading number.

                            This is incremented using SerialIncrement ( firstEnumeration ; 1 )

                            The default choice for firstEnumeration is "1. " when firstEnumeration is empty.




                               listCountText = Case(

                                  IsEmpty(firstEnumeration); "1. ";


                               ) // End Case



                               IsEmpty(text); "";

                               ValueCount(text) = 1; listCountText & GetValue(text; 1);

                               listCountText & GetValue(text; 1) & "¶" &

                               NumberTheList(RightValues(text; ValueCount(text) - 1); SerialIncrement(firstEnumeration; 1))

                            ) // End Case

                            ) // End Let




                            • 11. Re: Add numbered paragraphs

                              Yes that is the end goal.

                              • 12. Re: Add numbered paragraphs

                                I like this.


                                I was thinking about making every page a new record, but the added flexibility  of breaking down every paragraph would give me more options down the line.

                                • 13. Re: Add numbered paragraphs

                                  Experience talking.

                                  For adding boilerplate to a list of line items (Quotes, for example), I found it easier to have new "Item" records to link to the paragraphs. Then the report prints so much nicer than with long (multi-paragraph) along with the labor, service or product line items.

                                  Clients loved the flexibility. A sortOrder field helps.