7 Replies Latest reply on Oct 26, 2010 11:41 AM by LaRetta_1

    removing leftmost pattern in calculation

    JulienBeauviala

      Title

      removing leftmost pattern in calculation

      Post

      Hello all,

      in a calculation field, I have the following :

      ¶ &

      If ( (periodicite ≠ "")     ; ". - " & periodicite ; "" ) &
      If ( (note_generale ≠ "")   ; ". - " & note_generale ; "" ) &
      If ( (note_titre ≠ "")      ; ". - " & note_titre ; "" ) &
      If ( (note_edition ≠ "")    ; ". - " & note_edition ; "" ) &
      If ( (note_adresse ≠ "")    ; ". - " & note_adresse ; "" ) &
      If ( (note_collection ≠ "") ; ". - " & note_collection ; "" ) &
      If ( (note_reliure ≠ "")    ; ". - " & note_reliure ; "" ) &
      If ( (note_contenu ≠ "")    ; ". - " & note_contenu ; "" )

      &
      ¶ &

      which is simple and serves it's purpose but leaves me with an
      extra '. - ' at the beginning of that block of text.

      I'm trying to get rid of that initial '. - ', but I'm having
      problems expressing that in filemaker speak (using text functions).

      Ideally I'd put the whole string into a variable, then split
      the variable on the first occurence of '. - ' and use the
      second part as what to display (well, thats what I would do
      if I was in php, but here in FileMaker, I'm not sure it
      would be the right way).

      Would someone have a pointer for me ?

      Thanks !

        • 1. Re: removing leftmost pattern in calculation
          philmodjunk

          ¶ &

             Let ( String = //put your if functions here ;
                     Right ( String ; Length ( String ) - 4 ) 
                    ) /* let */

          &
          ¶ &

          I subtract 4 because I am counting 4 characters in that leading text, 2 spaces, a hyphen and a period, that you want omitted.

           

          • 2. Re: removing leftmost pattern in calculation
            JulienBeauviala

            Brillant ! That exactly solves the issue.

            Thanks a bunch !

            • 3. Re: removing leftmost pattern in calculation
              LaRetta_1

              Here is another approach which drops the nested If()s … so instead of solving only the removal of the beginning “. – “ by wrapping YOUR calculation with Phil's suggestion, maybe you can instead fix the overall calc:

              Substitute (
              List ( periodicite ; note_generale ; note_titre ; note_edition ; note_adresse ; note_collection ; note_reliure ; note_contenu )
              ; ¶ ; ". - " )

              Nested If()s are very difficult to administer and understand and require several needless evaluations.  This is just another approach. :^)

              UPDATE: Just to explain a bit ... the List() function takes the values of a field and separates them with a carriage return () but if the field is empty, it is skipped.  So we use the List() function to grab all the fields you want.  Then we take the list which ends up in a string down the page and replace the carriage return with your desired beginning text of ". - "

              • 4. Re: removing leftmost pattern in calculation
                philmodjunk

                They're not really nested, they're in a chain linked by ampersands which makes it a little bit simpler to deal with, but LaRetta's solution is still an excellent way to simplify it.

                • 5. Re: removing leftmost pattern in calculation
                  LaRetta_1

                  You are right, Phil, they are not nested but I saw the extra unnecessary wrap of parentheses and didn't look any further and moved to rewriting the calc instead:

                  If ( (periodicite ≠ "")     ; ". - " & periodicite ; "" ) & 

                  For future considerions when using the If() function, it is suggested to use:

                  If ( IsEmpty ( periodicite ) ; ".-" & periodicite ) &

                  If no default result is specified, none is produced  so you can drop the portion in blue above entirely.

                  • 6. Re: removing leftmost pattern in calculation
                    philmodjunk

                    I'm well aware that ;"" isn't needed in the If functions we are discussing. You and others have pointed that out before. Wink

                    I prefer to put it in as it makes it a touch easier (in my mind, but maybe I'm just being old fashioned as this wasn't an option in older versions of Filemaker as near as I can remember), and I think it can avoid confusion for new users who may not be as familiar with how If functions work as you and I are.

                    It's purely a preference on my part.

                    • 7. Re: removing leftmost pattern in calculation
                      LaRetta_1

                      Yes, I knew you were aware that default result wasn't necessary.  I had been speaking to Julien about the 'further considerations' but I didn't specify that.Laughing