6 Replies Latest reply on Mar 31, 2014 9:14 AM by leftear13

    Replacing Value

    leftear13

      Title

      Replacing Value

      Post

           How would I go about replacing the value of height and width in an iFrame code?

           <iframe width="560" height="315" src="//www.youtube.com/embed/0RdrPzHeIpk?rel=0" frameborder="0" allowfullscreen>

           When our suppliers submit new products to us, they sometimes include a promotional video which we then embed on our website, but most all have different widths and heights  (width="560" height="315").  Rather than changing them manually, we'd like to change/replace those values only with, for example 300 as the width and 150 as the height, to keep it consistent when posted on our website.

           Can't get my head around how to achieve this in Filemaker.

           Any insight?

           Thanks!

            

            

            

        • 1. Re: Replacing Value
          philmodjunk

               Let ( txt =  YourTable::YouriFrameTextFieldGoesHere ;
                      "<" &  Leftwords ( txt ; 1 ) & " width = \"300\" height = \"150\" " & Rightwords ( txt ; WordCount ( txt ) - 5 ) & ">"
                     ) // let

          • 2. Re: Replacing Value
            leftear13

                 Wow, I would have never figured that out.   

                 Works perfectly, Phil, thanks a lot!

            • 3. Re: Replacing Value
              philmodjunk

                   It's not the only option. It may fail if the iframe text does not consistently place the width and height tokens in the same place in every instance. There are other methods that use the Position function to find the precise location of text such as "width =" and uses that to compute how to parse the text in a string of this sort.

              • 4. Re: Replacing Value
                leftear13

                     i just ran it for a series of products and it replaced all accordingly.   Worked great!

                     The only thing is that some products don't have a promo video, thus the field is blank and should remain blank. The script I used with your code populated those blank ones with <width = "560" height = "315" > only in the field.  This make sense considering the script I used was Replace Field Contents (which I shouldn't have used), but how to prevent that?  Would like to replace only those products with a promo video.

                     Thanks

                      

                • 5. Re: Replacing Value
                  philmodjunk

                       Use an If function to check and see if the field is empty.

                       If ( Not IsEmpty ( YourTable::YouriFrameTextFieldGoesHere ) ;
                             Let ( txt =  YourTable::YouriFrameTextFieldGoesHere ;
                                      "<" &  Leftwords ( txt ; 1 ) & " width = \"300\" height = \"150\" " & Rightwords ( txt ; WordCount ( txt ) - 5 ) & ">"
                                    ) // let
                            ) // If

                       Note: // is a comment operator. All text to the right of // will be ignored in a calculation.

                  • 6. Re: Replacing Value
                    leftear13

                         Bingo!  You're the goods, Phil, thank you.