8 Replies Latest reply on Feb 25, 2014 3:58 PM by rmittelman

    New to FM...

    tguise

      "THANKS in Advance" to anyone who has a moment to read the following and provide "any guidance", even if it is "quit while you are ahead" ...lol

       

      After purchasing FM Pro 12 and going through the first 7 FM Tutorials and a ref book or so, I knew this would be interesting... I just didn't know how interesting...

      (Bkgrnd: BAL, DB2, C, VB6, Dbase... 10-12 years ago...)

       

      After building some layouts using TAB's I realized you can't change the Ref Tables, so I built multiple nested interactive tabs (& tables) and that was OK... I have had some successes, but this one...

       

      Q1:

      While I know that you can place a field on a layout then check Calculate and (for example) provide the text formatting code to format a 10 digit phone number.

      (ie) Table::Field = "(" & Left ( Phone ; 3 ) & ") " & Middle ( Phone ; 4 ; 3 ) & "-" & Right ( Phone ; 4 ) Works well...

       

      That being said, what if one wants to use a Set Script Trigger "OnObjectExit()" so as to better understand what is happening under the hood?

       

      Enter 8005551212 into layout field

      Script "Format_PhoneNum"

      ....

      Set Variable [$input1; TestTbl::phone_field]

      [Debug/Data View] TestTbl::phone_field 8005551212

      $input1 8005551212

      $input2

       

      Set Variable [$input2; "(" & Left ( $input1 ; 3 ) & ") " & Middle ( $input1 ; 4 ; 3 ) & "-" & Right ( $input1 ; 4 )

      [Debug/Data View] TestTbl::phone_field 8005551212

      $input1 8005551212

      $input2 (800)^555-1212

       

      Set Field [TestTbl::phone_field=$input2]

      [Debug/Data View] TestTbl::phone_field 0

      $input1 8005551212

      $input2 (800)^555-1212

       

      While starring at this off and on for a few days, I have tried other versions in an attempt to write a <$variable> into a Table::Field. Each time the result was not successful.

       

      (Very new to FM but trying to catch up...) Any insight is appreciated and "Thanks" again.

        • 1. Re: New to FM...
          cwiltgen86

          Can you send a screen shot of the actual script?  Are all the fields Text Fields?

          • 2. Re: New to FM...
            tguise

            Test Script.jpg

            • 3. Re: New to FM...
              cwiltgen86

              I think your SetFieldIs Wrong.  there are two Specify buttons on the script step.  the first is for the field you are setting the second is the value you are assigning.  when all said it should look like this

               

              Set Field [ TestTbl::phone_field; $input2]

              • 4. Re: New to FM...
                Malcolm

                use the set field function. When the Set Field script step is highlighted there are two buttons in the lower right hand corner. One button is used to select the field which is the target which receives the data. The other button is used to enter a calculation which generates the data.

                 

                To input a variable, simply type the variable name, e.g., $input2

                 

                To input a calculation, enter the calc, e.g., "(" & Left ( $input1 ; 3 ) & ") " & Middle ( $input1 ; 4 ; 3 ) & "-" & Right ( $input1 ; 4 )

                 

                Malcolm

                1 of 1 people found this helpful
                • 5. Re: New to FM...
                  erolst

                  You don't have to use a script to format a field's content on the fly; that's what an auto-enter calculation is for (Manage Database, Fields tab, Options, Auto-Enter tab). Enter your calculation and uncheck the "Do not replace …" option unchecked, so subsequent changes trigger a re-calculation.

                   

                  Simply use your first calculation; you can replace the field reference with the Self keyword:

                   

                  "(" & Left ( Self ; 3 ) & ") " & Middle ( Self ; 4 ; 3 ) & "-" & Right ( Self ; 4 )

                  • 6. Re: New to FM...
                    tguise

                    Thanks to all who responded.

                     

                    It was not clear that the objective was to use both buttons. It seemed it was one or the other.

                     

                    This clears up several issues regarding script functions.

                     

                    Thanks again to all!

                    • 7. Re: New to FM...
                      tguise

                      Thanks! Indeed you are correct. Using "both" buttons resolves the issue and several other ones.

                      Thanks Again!

                      • 8. Re: New to FM...
                        rmittelman

                        I have used a somewhat different solution.  I have a "Phone" text field in my table, enforced as numeric only with a maximum of 10 digits.

                        I also have a "PhoneFormat" calculation field with the following formula:

                        If ( not IsEmpty ( Phone ) ;  If ( Length ( Phone ) = 10 ; "(" & Left ( Phone ; 3 ) & ") " & Middle ( Phone ; 4 ; 3 ) & "-" & Right ( Phone ; 4 ) ; "Invalid Phone" ) ; "" )

                         

                        This basically returns "" if there is no phone number in "Phone", or "Invalid Phone" if not exactly 10 digits, or the formatted phone number like (###) ###-####.

                        On my layouts, I add a field for PhoneFormat, and UNCHECK everything in the "Field Entry" section. This field is immediately on top of the Phone field, and is NOT a tab stop.

                        When tabbing through the form, when the focus gets to the Phone field, the user types in 10 digits, and when the field is exited the PhoneFormat field again becomes visible.  This seems to work just fine. 

                         

                        FMP (even 13) seems to have a validation quirk.  If I limit the length to 10, then enter 11 digits and tab off the field, it immediately warns me and I need to go back to the field and correct it.  If instead I validate by calculation and that calculation says must be exactly 10 digits, the validation does not happen until I leave the record.  This is why I used the calculation in PhoneFormat to display an error message, which it does immediately.