8 Replies Latest reply on May 18, 2016 7:43 AM by OddbjørnAase

    Can I use if-then-statement inside a text field?

    OddbjørnAase

      I have a little text block saying how many people in a spesific found set where the number is a merge field. If it is one person, the word after it should be in singular, if it is more than one person, the word should be in plural. This can be done in many ways, but I also wonder generally; how can I tell filemaker that some function is coming, rather than straight text? The merge field starts and ends with << >>, I guess something similar can be used to use functions?? I have not found anything anywhere about this… Maybe it can't be done?

        • 1. Re: Can I use if-then-statement inside a text field?
          stephensexton

          An unstored calculation field based on Get(FoundCount) may help based on your question.  An unstored calculation field displayed on your layout can result in a performance hit.  In the case of found count and total record count, I haven't observed any significant impact on performance however in my case. 

           

          Other options:

           

          1. You could paste the following in a text object on the layout:

           

          {{RecordNumber}} / {{FoundCount}} ({{TotalRecordCount}})

           

          2. You could use the above merge fields in combination with the "Hide Object When" feature, that you can access in the Inspector window.  For example... one merge field on top of another, whereby one of them will be hidden in a given circumstance - e.g. only show one of the merge fields if Get(FoundCount) is greater than 1 (plural)

           

           

          Hope that helps

          1 of 1 people found this helpful
          • 2. Re: Can I use if-then-statement inside a text field?
            user19752

            No.  "Text block" don't allow any calculation.

            You can use "button bar" instead (only for FM14 or newer).

            1 of 1 people found this helpful
            • 3. Re: Can I use if-then-statement inside a text field?
              erolst

              user19752 wrote:

              You can use "button bar" instead (only for FM14 or newer).

               

              i.e. make the bar only one segment wide, and mis-use that segment's label calculation.

               

              To cater for scenarios where you need more field-like (“fieldish”?) behaviour: create a dummy global field, put it on the layout and use its placeholder calculation.

               

              That field will always be empty, and every instance of it (i.e. field object) on a layout can have a different placeholder calculation. Define once, use often …

              1 of 1 people found this helpful
              • 4. Re: Can I use if-then-statement inside a text field?
                beverly

                a text FIELD is an object. The field can be text (formatted or not) or calculated text (formatted or not).

                a text BLOCK is an object in the background of the layout. The block of text can be formatted or not. The block of text can contain MERGE FIELDS and SYMBOLS (both found under the Insert menu). The block of text is not calculated, but  can contain calculated fields (as merge fields).

                 

                Only by calculation can you change the value of a word from singular to plural within text (in a field).  You can change formatting on individual elements (characters or words) in the block of text, but that is styles such as bold or font or number/date formatting, such as currency.

                 

                You can also insert MERGE VARIABLES in a block of text. These look like

                $$someVar

                If you have a method to change the variables, then the text will change as the variable changes. I like to use scripts to set these (basically calculating the text values). They must be 'triggered' in some way to change.

                 

                The If-Else statement (function) is ONLY in the calculation itself. You cannot apply conditions to a single word that is part of a block of text (as field or merge field or merge variable).

                 

                1 doctor

                3 doctors

                 

                the "s" must be calculated in some way.

                beverly

                1 of 1 people found this helpful
                • 5. Re: Can I use if-then-statement inside a text field?
                  siplus

                  You CAN have calculations in a text block, to a certain extent.

                   

                  See attached example.

                  1 of 1 people found this helpful
                  • 6. Re: Can I use if-then-statement inside a text field?
                    beverly

                    Yes and no.

                    You used a calculation in the conditional formatting and refreshed the window with a trigger. I don't care for this method as it can be too hard to debug. JMP (just my preference!) But maybe OP likes to use it.

                    BTW. "0" would also use the 's'...

                    beverly

                    1 of 1 people found this helpful
                    • 7. Re: Can I use if-then-statement inside a text field?
                      OddbjørnAase

                      Thank you!

                      I can certainly learn a lot from all these answers - great!

                      • 8. Re: Can I use if-then-statement inside a text field?
                        OddbjørnAase

                        Each reply is helpful to me in different ways, so thank you all!!