3 Replies Latest reply on Jul 8, 2015 5:40 PM by disabled_JustinClose

    FM9 calculation fails, but works in FM11?

      Title

      FM9 calculation fails, but works in FM11?

      Post

      I was doing a bit of work for a client who is running FM9 clients, connecting to a file hosted on an FM11 server.  I don't have FM9, so was doing development on FM11.  I thought I had checked out that everything was compatible, but I somehow generated a calculation that doesn't evaluate on 9, but does on 11.  The components of the calculations and custom functions used all appear to be innocuous...  I  am hoping someone here knows what I tripped up on.

      Here's the field calculation, and the 2 custom function definitions that it uses.  The entire point of this calculation is to take a mish-mash text field that they have and make it sort nicely.  For this bit I added, I'm just concerning myself with sorting some suffix numbers that occur between parentheses, e.g. 12345(A-1).

       

      Field calculation definition:
      
      Let ( [
      _fileNum = Files::File Number ;
      
      //Position of 1st open/close parens, and then extract the text between them:
      _sParen = Position ( _fileNum ; "(" ; 1 ; 1 ) + 1;
      _eParen = Position ( _fileNum ; ")" ; 1 ; 1 ) ;
      _suffix = Middle ( _fileNum ; _sParen ; _eParen - _sParen) ;
      
      //Count the leading digits before any non-digit character, e.g. an alpha, or dash or space, etc.
      _count = CountPrefixDigits ( _suffix ; 0 ) ;
      
      //Remove extraneous characters (dash, space):
      _suffix =  Substitute ( _suffix; ["-";""]; [" " ; ""] ) ;
      
      //Pad out the string to min 5 characters (helps 75-A sort next to 75):
      _suffix = _suffix & Left ( "!!!!!" ; 5 - Length (_suffix) );
      
      //Reverse the character sequence (so the Code() call works out better):
      _suffix = ReverseString ( _suffix )
      ];
      
      _count & Code ( _suffix )    //prepend the digit count, but don't encode that count, just the rest of it
      
      )
      
      --------------------
      'CountPrefixDigits ( aString ; aCounter )' custom function:
      
      If (
          IsEmpty ( GetAsNumber ( Left ( aString ; 1 ) ) ) ;
          aCounter ;
          CountPrefixDigits ( Right ( aString ; Length ( aString) - 1 ) ; aCounter + 1 )
      )
      
      --------------------
      
      'ReverseString (aString)' custom function:
      
      If (
          Length ( aString ) > 0 ;
          ReverseString ( Right ( aString ; Length ( aString ) - 1 ) ) & Left ( aString ; 1 ) ;
          Left ( aString ; 1 )
      )

      Thanks,

      Justin