6 Replies Latest reply on Jul 28, 2016 9:50 AM by bobcopus

    Begins with calculation

    talkersw

      I know this is a really easy one for someone but I don't want to tinker with it. How do I specify a field beginning with certain letters in a calculation. For example, I thought I could do it this way:

       

      Assume my calculation says if field begins with "AOT"

       

      FIELDNAME == AOT*

      ..I tried quotes on "==" and some other things but not working.

        • 1. Re: Begins with calculation
          beverly

          try the Left() function

          If ( Left(fieldname; 3) = "AOT" ... )

          Of course that is only part of the test. What do you want to do with the results?

           

          A calculation field can be created that is just:

          Left ( FIELDNAME ; 3 ) // return the first 3 characters

           

          Then you can use the value, search the field, sort the field, etc.

          beverly

          • 2. Re: Begins with calculation
            beverly

            And you can FIND in you field as searches are already "begins-with".

             

            Enter Find mode

            Set Field ( FIELDNAME ; "AOT*" )

            Perform find

             

            no need for a calculation. again it depends on what you want to do with the value(s).

            1 of 1 people found this helpful
            • 3. Re: Begins with calculation
              talkersw

              Yes, sorry. I am using it in an if statement and triggered on an object save as the field is left. I didn't want to use a validation calc for it. Then will use a custom dialogue if it doesn't start with "AOT" because I know it was entered incorrectly. I have some others for length of char, etc..

              • 4. Re: Begins with calculation
                philmodjunk

                Then Beverley's suggestion on using the Left function would seem appropriate. But I'd consider OnObjectValidate instead of OnObjectSave if you are using a script to validate the input. This gives you better options for how your script can respond to data entry errors that fail the script's validation test.

                • 5. Re: Begins with calculation
                  talkersw

                  Yes that seems to be the best option. Thanks to you and beverley. Great community!

                  • 6. Re: Begins with calculation
                    bobcopus

                    Here's a generalized custom function that you might want to consider:

                     

                    // StartsWith ( text; startString )

                     

                    // This function determines if a text value starts with a particular substring:

                    // • Returns 1 (true) if it does; 0 (false) if it doesn't.

                     

                    // Parameters:

                    // • text The text to be checked

                    // • startString The substring we're looking for

                     

                    // Exception Conditions:

                    // • If the text value is empty or is not as long as the starting string, return 0.

                    // • If the text value is nonempty but the starting string is empty, return 1 (a null substring is an automatic match).

                     

                    // The match is NOT case-sensitive.

                     

                    Let (

                     

                      startStringLength = Length ( startString ) ;

                     

                      Case (

                     

                      /* No text to search */ IsEmpty ( text ) ; 0 ;

                      /* Not enough text to search */ Length ( text ) < startStringLength ; 0 ;

                      /* Empty match string */ startStringLength = 0 ; 1 ;

                      /* Check for a match */ Left ( text ; startStringLength ) = startString

                     

                      )

                     

                    )