5 Replies Latest reply on Sep 6, 2012 10:48 AM by philmodjunk

    How to find the start and end of data in a field

    PeterMontague

      Title

      How to find the start and end of data in a field

      Post

      I used the following script to find the start and end of the data in a field. But its not working for me. Can anyone see anything wrong with this script?

      If [this:: Start Content <> ""]

      Set field [this::gTempText; Middle9this::gTempText; Position9this::gTempText: this::Start Content; 1; 1) + Length9this::Start Content0; Length(this::gTempText))]

      End If

      If [this::End Content <> ""]

      Set Field [this::gTempText; Left(this::gTempText: Position9this::gTempText: this::End Content; 1; 1) -1)]

      End If

        • 1. Re: How to find the start and end of data in a field
          philmodjunk

          Reformatting what you have to make it easier to read:

          If [this:: Start Content <> ""]
                 Set field [this::gTempText; Middle ( this::gTempText;
                                                                     Position(this::gTempText; this::Start Content; 1; 1) + Length(this::Start Content );
                                                                     Length(this::gTempText))]
          End If

          If [this::End Content <> ""]
                 Set Field [this::gTempText; Left(this::gTempText; Position( this::gTempText ; this::End Content; 1; 1 ) -1 )]
          End If

          This looks correct. When I copy and paste the Middle function into the data viewer and use Let to assign values to gTempText and Start Content (Subbing variables for the field names) it and the left function work. I did have to change some colons to semi-colons however. (shown in red above).

          Once I changed the colons into semi-colons, the expressions evaluated correctly.

          What results are you actually getting when this fails to work for you?

          • 2. Re: How to find the start and end of data in a field
            PeterMontague

            I'm building quite a complicated script with many steps. I want to download the source code of a web page, clean it up and then parse out the bits that I need. The first step in the script that is giving me difficulties is the following:

            Set Field [this::gTempText; this::Child Source Code]

            This step puts the source code in the gTempText field. But afterwards when I run the rest of the steps the computer labours for about a minute but the gTempText field remains the same.

            I was just wondering, actually, if I really need to clean up the text of this very long source code at all? It makes it easier to parse the text but it take my computer a full minute or more to process. Why does it take so long? I have 4MB of RAM on my computer.

            Is it possible to parse a source code with all of the spaces and html tags etc. still there?

            • 3. Re: How to find the start and end of data in a field
              philmodjunk

              Your code is correct as far as I can tell from here. Thus, you'll need to check other details. How much data are you putting in gTempText? Is it a field of type text or number? Is it indexed? As a global field--what is usually meant by the g naming convention it won't be indexed, so make sure that global storage is specified.

              Text fields in FileMaker can store truly massive amounts of data, but there could be a delay if indexing is turned on and you are setting this field to a really large block of text. This should not be an issue if the field is global, but if not it would explain the delay.

              If you Have FileMaker Advanced, I suggest using the debugger and data viewer to monitor your script and this field step by step. If you do not, you can add some show custom dialog steps that display the contents of this field or at least a portion of the field to monitor the values in the field.

              Make sure that gTempText is a text field with global storage specified.

              • 4. Re: How to find the start and end of data in a field
                PeterMontague

                I checked the field and it has global storage. It is not indexed. I don't have FM Pro advanced on my computer where I am at the moment. 

                I added a custom dialog step to include the content of the field in the message.

                The dialog box comes up blank.

                Would you mind taking a look at the clean up result script, which includes the other script steps and tell me why it is so slow and what am I doing wrong?

                Here is a link to a copy of the database with just one record in it.

                The script is running in the table called 'this'.

                https://www.dropbox.com/s/vvg0nwqrniifnr2/database%20with%20script%20problems.fp7 

                • 5. Re: How to find the start and end of data in a field
                  philmodjunk

                  Instead of examing your file, try posting your script here.

                  To post a script to the forum:

                  1. You can upload a screen shot of your script by using the Upload an Image controls located just below Post A Answer.
                  2. You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF to your clipboard for pasting here.
                  3. If You have FileMaker Advanced, you can generate a database design report and copy the script as text from there.
                  4. If you paste a text form of the script, you can use the Script Pretty box in the Known Bugs List database to paste a version that is single spaced and indented for a more professional and easier to read format. (Use the HTML option on the database tab panel and paste the text into the forum's HTML editor.)