1 2 Previous Next 28 Replies Latest reply on Aug 4, 2015 2:35 AM by user14047

    Count lines in a textbox

    ianselmo

      I need to find a way to count the lines in a text box. I want to validate that the maximum lines allowed is not exceed because I transfer the information to a PDF files and i need to validate the maximum or else i cannot see all the information. The number of caracters is not good for me because If they press 'Enter' to add lines it doesn't work

        • 1. Re: Count lines in a textbox
          Benjamin Fehr

          I wouldn't know how to do since letters have different width. ( i - e ).

          But this custom function promises what you're looking for:

          FileMaker Custom Function:ActualLineCount ( Text ; CharsPerLine )

           

          The parameter "CharsPerLine" shows that this can only be a approximation.

          • 2. Re: Count lines in a textbox
            Mike_Mitchell

            And please don't double-post the same question. Thanks.

            • 3. Re: Count lines in a textbox
              ianselmo

              thank you

              • 4. Re: Count lines in a textbox
                siplus

                Very interesting problem: a simple request and an almost impossible answer.

                 

                Or not ?

                 

                What I would try to do is the following:

                 

                1) Put the text field all alone on a very tall layout. You know how many lines a single page of this layout holds - just count them in layout mode (the ........ lines). Save the original text into a global, or use the global on the layout and transfer the original text into it at the beginning of the script.

                 

                2) Go into preview mode, go to the last page and mark down how many pages there are. Let's call that P0.

                 

                3) Enter a loop that adds to the text a Lorem Ipsum - like line and a ¶, a line that you know for sure occupies a complete line. Go again in preview mode and go to the last page. Store that in P1.

                 

                4) stop when P1 > P0 and watch how many times you looped.

                 

                You know how many lines you have on a page and you know how many lines you added in order to make a page number increment, so you can deduct how many lines you had before starting to add full text lines to the original.

                • 5. Re: Count lines in a textbox
                  schamblee

                  There are too many variables for this to work reliably.  Font height, font style, type font, and margins are all factors in how many character will on one line and the height of the font affects the number of lines.  You will have more lines on a page if you use a 10 point font instead of a 12 point font or less lines if you use 14 or 18 point font.  What about mix font sizes, which is very common ?

                   

                  Good Luck   

                  • 6. Re: Count lines in a textbox
                    electon

                    Do you mean how many new lines or to how many lines the particular input field is wrapped to on a layout?

                    If it's the first than use a calculation:

                     

                    Let (

                      returns = PatternCount ( Trim ( test field ) ; "¶" ) ;  // count the number of new lines

                      If ( GetValue( test field ; returns + 1 ) ; returns + 1 ; returns )  // this to check if text after last return is not empty

                    )

                     

                    Otherwise you're in trouble because you would need to define the initial height and width of the actually printed field, then get the resulting H/W, and use some math. Even in html it's unpredictable unless you allow only one font size.

                    • 7. Re: Count lines in a textbox
                      Benjamin Fehr

                      counting CR (¶) will not work since line breaks get's applied automatically by the field border left.

                                                                                                                                                                                                            …… though in this line is no ¶ you could count

                      • 8. Re: Count lines in a textbox
                        Mike_Mitchell

                        You can approximate this (and reduce the variability) by:

                         

                        1) Restricting the font to a known typeface (preferably fixed width) and size.

                        2) Applying a rule such as "X characters per line".

                        3) Adding the number of carriage returns as additional lines.

                        4) Adding 1 if the last character is not a carriage return.

                         

                        However, as several folks have pointed out, this will never be precise. It largely depends on "how close is close enough".

                        • 9. Re: Count lines in a textbox
                          electon

                          Not sure if I follow.

                          If I type the same paragraph that wraps within the boud field it does not insert a CR in there.

                          Counting only works for new lines with CR ( enter or return ).

                          • 10. Re: Count lines in a textbox
                            schamblee

                            That is why it would not be reliable and as efficientbizz stated, it will not work.  The best that can be done is a close approximation.  They always say that close only counts in horse shoes and hand grenades, I guess you can determine if counting CR is close enough.

                            • 11. Re: Count lines in a textbox
                              sporobolus

                              On 2015-02-09 9:32 , ianselmo wrote

                              I need to find a way to count the lines in a text box. I want to validate that the maximum lines allowed is not exceed because I transfer the information to a PDF files and i need to validate the maximum or else i cannot see all the information. The number of caracters is not good for me because If they press 'Enter' to add lines it doesn't work

                               

                              as others have pointed out, this comes down to being able to know how the

                              lines "lay out" based on fonts & any formatting applied; i doubt you want to

                              go to as much trouble, but i have done it with this strategy:

                               

                              you will need to know what fonts the text might use, and load tables of font

                              metrics; then add up the width of each character based on its specific font

                              and size, and account for how lines are allowed wrapped (generally at spaces

                              and punctuation); you'll then have the number of lines; if your lines vary

                              in height (different fonts), you'll need more work to know the vertical

                              space consumed

                               

                              this is more work to implement than most people would want, but definitely

                              doable; i did it to calculate whether telephone directory listings would fit

                              on one line, so i didn't have to worry about line height, and i had a

                              limited number of fonts to worry about

                              • 12. Re: Count lines in a textbox
                                user14047

                                Sample File

                                Use GetLayoutObjectAttribute ( objectName ; "height" )

                                • 13. Re: Count lines in a textbox
                                  rgordon

                                  I think this sample file will consistently accomplish what you want.  It is similar to what siplus posted.

                                  • 14. Re: Count lines in a textbox
                                    rgordon

                                    Please remove the double post.   This discussion was posted twice and now there are replies to both discussions which makes it difficult to follow.

                                    1 2 Previous Next