5 Replies Latest reply on Oct 4, 2012 9:46 AM by philmodjunk

    Help with downloaded custom function

    galeton

      Title

      Help with downloaded custom function

      Post

           I found a custom function on Brian Dunnings website called title (text; leaveempty) that I am trying to implement in my program. I have never used custom functions before. Here is a copy of the function:

           Let ( [

           prefixList = "Mc";
           alwaysLower = "a¶an¶and¶aka¶at¶by¶for¶ie¶in¶is¶it¶nor¶of¶on¶or¶the¶to¶vs¶vs.¶w/¶with";
           alwaysUpper = "AC¶EMI¶RCA¶ABC¶INXS¶REM¶UB40¶UK¶USA¶OK¶USSR¶MTV¶NRG¶DJ¶MC¶H2O¶CD¶NY¶NYC¶ID¶EP¶TV";

           prevText = LeaveEmpty;
           nextText = case(isempty(prevText) and Exact( Text, Upper(Text) ), lower(Text), Text);

           prevChar = Right( prevText; 1);
           prevChar_preSpace = Right( Trim(prevText); 1);
           prevChar_isUpper = Exact( prevChar_preSpace; Upper(prevChar_preSpace));
           prevChar_isLower = Exact( prevChar_preSpace; Lower(prevChar_preSpace));
            
           prevCaseType = Case(
              prevChar = " "; Case(prevChar_isUpper and prevChar_isLower; "symbol"; "space");
              PatternCount("0123456789"; prevChar); "number";
              prevChar = "'"; "apos";
              prevChar_isUpper and prevChar_isLower; "symbol";
              prevChar_isLower; "lower";
              prevChar_isUpper; "upper");
              
           currWord = RightWords(prevText; 1) & Left(nextText; Position(nextText & " "; " "; 1; 1)-1);
           currChar = Left(nextText; 1);

           /************************ PLEASE READ THE COMMENTS BELOW ***********************/
           /******** THEY MAY HELP YOU WITH TWEAKS THAT BETTER FIT YOUR SITUATION *********/

           currCase = Case (
                 // First character of the title is always uppercase
              IsEmpty ( prevText ); "upper";
                 // Always capitalize the first letter after any symbol
                 //   except an apostrophe (which is handled separately), even if that symbol
                 //   was followed by spaces (avoids an alwaysLower word from being lower if
                 //   it is really the beginning of a sentence)
              prevCaseType = "symbol"; "upper";
                 // Make it lowercase if it is in your alwaysLower value list
              WordCount( nextText ) > 1 and prevCaseType <> "symbol"
                   and not IsEmpty( FilterValues( LeftWords ( nextText; 1); alwaysLower)); "lower";
                 // First letter after a space is always capitalized (unless it
                 //   was one of the previous arguments, like alwaysLower)
              prevCaseType = "space"; "upper";
                 // Make it uppercase if it is the first character after an item in your prefixList
              not IsEmpty ( FilterValues( RightWords(prevText; 1); prefixList ) ); "upper";
                 // The letter after an apostrophe is uppercase if there are more than a couple characters
              prevCaseType = "apos" and Length ( LeftWords(nextText; 1) ) > 2; "upper";
                 // Make it uppercase if it is in your alwaysUpper value list
              not IsEmpty( FilterValues( currWord; alwaysUpper)); "upper";
                 // The character after a number is always lowercase (to handle something like "19th")
              prevCaseType = "number"; "lower";
                 // You may or may not want this, as it helps but is imperfect.  
                 //   It makes a "word" without vowels into all caps.
                 //   This will result in converting 'lcd' to 'LCD', which is probably desirable.
                 //   But it won't convert 'led' to 'LED' because 'Led' could also be a word.
                 //   It also tests for a period so that 'mrs' will convert to 'Mrs.'
              IsEmpty( Filter( currWord; "aeiouyAEIOUY")) and not PatternCount(currWord; ".")
                  and prevCaseType <> "lower"; "upper";
                 // You may or may not want this, as it may or may not help your situation.
                 //   It makes it possible to enter 'LaFond' and keep it that way (as opposed
                 //   to 'Lafond').  The down side of this is that you may prefer to just
                 //   overwrite your users' potential inconsistencies.  
                 //   Either way, it is imperfect for all situations.
              prevChar_isLower and Exact ( currChar; Upper ( currChar ) ); "upper";
              "lower" );

           /************** TWEAKING NOT RECOMMENDED BELOW THIS LINE ****************/

           currChar = Case(
              currCase = "upper"; Upper(currChar);
              currCase = "lower"; Lower(currChar);
              "lower") ;

           nextText = Right ( nextText; Length ( nextText ) - 1 )

           ] ;    // end Let() parameters


           Case (
           IsEmpty (Trim(nextText)); prevText & currChar;
           Title(nextText; prevText & currChar)
           )

           )  // end Let() statement

            

           I think I need to add the parameters "LeaveEmpty" and "Text" to the parameter list in the function. But how do these relate back to my "title" field in my database?  I would appreciate any help. I would love to learn how to use these custom functions. Thanks for you help.