12 Replies Latest reply on Feb 1, 2013 8:35 AM by Shauniedarko

    How Do I write: (if internet_field =)

    khk166@gmail.com

      Hello,

       

      In a script, I would like to test for a text string and anything after it. For example, I would like to say,

       

      if (internet_field = "www" and anything after it)

       

      then, do statements

       

      end if

       

      In a script, how do I say to Filemaker "www" and anything else? It doesn't like "www" & "*" or "www" & *.

       

      Please help. Thank you in advance.

       

      Ken

        • 2. Re: How Do I write: (if internet_field =)
          Shauniedarko

          I guess it all depends on what, exactly, you're trying to do.  If all you're trying to do is test for the "www" portion of the URL (I would assume to make sure that the URL is correctly formatted), then you could easily just test the first three letters by using:

           

          If(Left(internet_field ; 3) = "www")

           

          All that does is look at the first three letters of the URL and determine if they are "www".  If not, it returns false.  If you only care that the URL begins with "www" and don't care what comes after, then that will do it for you.

           

          However, if you're trying to validate the entire URL to make sure it's formatted correctly (www.domain.com), then you need soemthing a little more complex.

           

          S.

          • 3. Re: How Do I write: (if internet_field =)
            khk166@gmail.com

            Hi,

             

            Thank you very much for your reply.

             

            My question is this:

             

            I'm looking to test for anything after the "www". Therefore, I'm saying

             

            if (internet_field="www" and anything after it) then

             

            do statements

             

            end if

             

            However, sometimes I would like to test for an exact string after the

            "www". That's also something I don't know how to do.

             

            Again, thank you very much.

             

            Ken

            • 4. Re: How Do I write: (if internet_field =)
              khk166@gmail.com

              Hi,

               

              Thank you very much for your reply.

               

              Yes, you are very right with your suggestion to look at the two functions.

              I'm wondering if there is an operator in Filemaker which performs like an

              asterisk in some cases. In other words, if you can use a "*" to be a

              wildcard and signify any and all characters after the the string. In this

              case, the string being "www".

               

              Thanks again,

               

              Ken

              • 5. Re: How Do I write: (if internet_field =)
                Shauniedarko

                Like Martin suggested, the Position and PatternCount functions are going to be your friend. 

                 

                There are a few ways you can do it.  I'd suggest breaking the URL into it's three parts.  I'm assuming here that all the URLs you'll be dealing with will be formatted in the www.name.com format.  Then I'd break it down into the three parts and test each part for whatever you're looking for. 

                 

                Here's an example:

                 

                /*

                You can set this up as a Custom Function if you have FileMaker Advanced.  It might be preferable and would be more customizable.  However, this is the basic concept.  There are a lot of other ways to do this, this is just how I'd do it. 

                */


                //First, I use the Let function to set my parameters.  You can replace "url" with your own fieldname.


                Let([

                url = "www.company.com" ;

                t1 = PatternCount(url ; ".");


                /*

                What I've done in t1 is test to see if the URL is even formatted correctly by counting the periods.  So, t1 will return the number of periods in the url.  In t2, I started a Case statment that first tests to see if there are 2 periods in t1. If there are not, the error statement is returned.  If there are 2, then it continues.

                */


                t2 = Case(t1 ≠ 2 ; "A URL must be formatted in the following way: www.domain.com" ;

                               t1 = 2 ;

                                   Let([

                                         p1 = Position(url ; "." ; 1 ; 1);

                                         p2 = Position(url ; "." ; 1 ; 2);

                                         a1 = Left(url ; p1 - 1) ;

                                         a2 = Middle(url ; p1 +1 ; p2 - p1 -1 );

                                         a3 = Right(url ; Length(url) - p2)

                                    ];


                /*

                What I'm doing here is breaking down the url into three parts.  a1 will return "www", a2 will return "company", a3 will return "com".  The reason I choose to do this is because it's easier for me to test.  This is where the Position function becomes your friend.  Combined with the Left, Middle, and Right functions, it allowed me to isolate each section of the url.  You could use the LeftWords, RightWords, MiddleWords functions, but this, for me, is more precise. 

                */


                                       List(a1 ; a2 ; a3)


                /*

                Once I have the values, I use the List function to turn them into a list. The result for www.company.com will be:

                www

                company

                com

                */


                                    );

                          "" )


                ];



                /*

                With my values isolated, I can then use a Case statement to evaluate them based on my criteria.  Remember that a Case statement will evaluate until it returns true, so format it in such a way that it will fail first.  For example, if the first test of this Case statement was to test whether the URL ended in "com" while the second was to test whether the domain was "company1", the first test would return true and never tell you that the second test had failed.  So, in my example, I test for failure on each part before testing for success.

                */


                Case(

                GetValue(t2 ; 1) ≠ "www" ; "URL must begin with \"www\"";

                GetValue(t2 ; 3) ≠ "com" ; "URL must end in \"com\" " ;

                GetValue(t2 ; 2) ≠ "company" ; "URL formatted incorrectly" ;

                GetValue(t2 ; 2) = "company" ; "Good job!";

                ""

                )



                )



                 

                See if this gets you started.  Hope it helps

                Shaun

                • 6. Re: How Do I write: (if internet_field =)
                  khk166@gmail.com

                  Hello,

                   

                  Sorry for the delay in getting back to you.

                   

                  This is a wonderful explanation. Thank you for taking the time to really

                  expound upon pattern matching.

                   

                  Of course, I will implement some portion of the explanation to satisfy my

                  question. Originally, I had wondered:

                   

                  if ("www" and anything after it,)

                   

                  This I thought could be accomplished with an asterisk signifying

                  "anything". But, I guess not. It just goes to show you what I know.

                   

                  Anyway, thanks very much for taking the time.

                   

                  Ken

                  • 7. Re: How Do I write: (if internet_field =)
                    Shauniedarko

                    No problem.

                     

                    I suspect that once you have a handle on these concepts, you'll inevitably find a better way to accomplish what you want to do. 

                     

                    Good luck!

                     

                    Shaun

                    • 8. Re: How Do I write: (if internet_field =)
                      LyndsayHowarth

                      Remember, of course, that most non-US domains have 4 parts - adding a country code at the end of .com, .net, .asn.

                       

                      - Lyndsay

                      • 9. Re: How Do I write: (if internet_field =)
                        khk166@gmail.com

                        Yes, agreed. That is something that is important and something that I

                        didn't think of. Thank you.

                         

                        Ken

                        • 10. Re: How Do I write: (if internet_field =)
                          khk166@gmail.com

                          Hi Shaun,

                           

                          With a tip of my hat to your great explanation, I am constructing a custom

                          function to accomplish what I had set out to do. It should work very well.

                          I'm building into the conditional test wether or not to launch "Mail" or a

                          browser based on the content of the field. That is really the basis for my

                          question.

                          In years past, I had always used pattern matching and the "position"

                          function in both proprietary languages (4th Dimension, etc.) and C. I don't

                          know why I had brain rot this time, but I did.

                          So, after all of that, my original thought was that there would be built

                          into Filemaker a simple "*" asterisk function to be able to test for the

                          presence of any character. To be able to say, if www. exists and anything

                          after it, then do stuff. That would have been the simple way out. Go

                          figure, huh?

                           

                          Thanks again for your help.

                           

                          Ken

                          • 11. Re: How Do I write: (if internet_field =)
                            Shauniedarko

                            4D...ugh.  I worked in a database based on 4D and couldn't stand it. 

                             

                            You could actually use If("www.company.com" ≥ "www." ; "True" ; "False") to test for the presence of "www." and then anything after that.  The problem with that is that with such a test, someone could put in "www.beans.stupid" and it would pass the test.  Since that's not a valid address, it might defeat the purpose.  However, if it's really unimportant what comes after the "www." so long as SOMETHING comes after it, it would work.

                             

                            The downside I've found to FileMaker is that sometimes things that seem like they should be easy to accomplish aren't so easy. The upside is that once I've created the solution to my problem, I can make it into a custom function and achieve a greater flexibility than I would otherwise have.  So, there are tradeoffs, you know?  But above all, there's always more than one way to skin a cat.  Any problem you can come up with can have multiple solutions.  It's just a matter of finding one that works.

                             

                            S.

                            • 12. Re: How Do I write: (if internet_field =)
                              Shauniedarko

                              Yes!  I always forget about that.  The nice thing about solutions like these is that they're infinitely customizable.  That's one of the reasons I love FileMaker so much.