8 Replies Latest reply on Dec 5, 2011 9:13 AM by user

    Scripting a trim all

    user

      It's as simply put as the title i need some pointers on scripting a trim all. even if some one could give me the basic f/e a script to trim a single record. im sure i could figure it out from there.

        • 1. Re: Scripting a trim all
          fitch

          It depends what you mean by "trim all." The Trim() function works on a field. What do you mean by "trim a record?" (And what's "the basic f/e?") And would it need to be a script?

           

          Maybe this is what you want.

          • 2. Re: Scripting a trim all
            user

            Yes it needs to be a script. I need to trim all the leading spaces before

            and after for all of my data. and the f/e was a typo

            • 3. Re: Scripting a trim all
              beverly

              User (don't know your name, as you didn't sign the post), is this data that you imported from somewhere that had fixed-width (and thus spaces for "padding") columns?

               

              You can use the trim() function to remove leading and trailing spaces. You'd have to apply it to each field, something like this:

               

                   go to record      

                   view as

                   freeze window

                   loop

                        set field[field1; Trim(field1)]

                        set field[field2; Trim(field2)]

                        ... etc.

                        go to record

                   end loop

                   view as

               

              I do the list/form so you can "see" the selection go to each record.

               

              If you will be importing in the future, come up with a way to trim before import?

               

              Beverly

              • 4. Re: Scripting a trim all
                sporobolus

                on 2011-12-02 08:34 beverly wrote

                      go to record  https://fmdev.filemaker.com/message/64170#64170#64170/first Re: Scripting a trim all

                      view as  https://fmdev.filemaker.com/message/64170#64170#64170/list Re: Scripting a trim all

                      freeze window

                      loop

                           set field[field1; Trim(field1)]

                           set field[field2; Trim(field2)]

                           ... etc.

                           go to record  https://fmdev.filemaker.com/message/64170#64170#64170/next, exit after last Re: Scripting a trim all

                      end loop

                      view as  https://fmdev.filemaker.com/message/64170#64170#64170/form Re: Scripting a trim all

                 

                yet another victim of Jive's allergy to information in square brackets

                • 5. Re: Scripting a trim all
                  Stephen Huston

                  Beverly's closing comment about trimming before imports reminds me that you can more efficiently trim fields by doing an auto-enter evaluated calc on any field you want to trim, setting it to Trim(self) in the field definition.

                   

                  Then you won't need the script at all because simply entering the data in the field will cause it to trim itself.

                   

                  This will work during normal data entry, and during imports (if the perform auto-enter function is enabled for the import).

                  • 6. Re: Scripting a trim all
                    beverly

                    yes, Stephen is right. I was going to suggest the auto-enter. If you import excessively large sets of data, this can slow it down (each and every field!) Thus my suggestion to get it "trim'd" before import.

                     

                    Beverly

                    • 7. Re: Scripting a trim all
                      BruceHerbach

                      Another scripting option would be to use the replace field contents script step.

                       

                      Replace Field Contents[no dialog; field1; trim(field1)]

                       

                      This will replace the value in the desired field for all records in the current found set.  If you use it make sure you check the No dialog box and have exclusive access to the found set.  If it fails on a record because someone else has the record open,  it will report that there was a problem but doesn't tell you which record in the found set failed.

                       

                      Since this is an import my guess is this won't be a problem.

                       

                      Another tricks that can speed up a scipt that is processing a large found set is to do all of the work on a blank ( no fields at all ) layout in form mode. 

                       

                      Hope this helps

                      Bruce

                      • 8. Re: Scripting a trim all
                        user

                        Preciate this i had already got this script worked out but this is an

                        interesting way of doing it ill have to try it out sometime.