8 Replies Latest reply on May 7, 2013 11:26 AM by brian.curran

    Set Variable but format it at the same time?

    brian.curran

      Hi,

      Is it possible to set a variable and format it at the same time?

       

      I have a Time field that accepts 2224 and displays it as 22:24 even though the underlying data is actually 22:24:00

      When I set this field as a variable and then use 'Set Field' later, it pastes 22:24:00 which fails and leaves me with the a "?" as the result.

       

      Is there a way I can avoid this somehow?

       

      Thanks

      Brian.

        • 1. Re: Set Variable but format it at the same time?
          wimdecorte

          when you say "accepts 2224"; is that because you have an auto-enter calc that does something with the input?  If so what is that calc?

          • 2. Re: Set Variable but format it at the same time?
            brian.curran

            Sorry, I should have included the calc in my original post:

             

            /*ParseTime ( timeText ) =

             

            This function parses and reformats time (hours and minutes) casually entered into a text field so that it can be converted to a valid time by Filemaker. It also includes tests so that, if an invalid time string is entered, it will return an error message instead of an invalid time. Further, it incorporates code from the TimeMask custom function written by Steve Gerow of Abrazos Data Consulting that logically assigns AM or PM to times entered without that data between 7am and 7pm. It handles military time correctly as well. Many thanks to Steve, and to Brian Dunning. */

             

            Let (

            [

            nums = Filter ( BrokenTime ; "0123456789" ) ;

            chars = Filter (Upper ( BrokenTime ) ; "AMNP" ) ;

            lgthN = Length ( nums ) ;

            lgthC = Length (chars ) ;

            numTest = Case ( GetAsNumber ( nums ) < 1260 ; 1 ;

                                         GetAsNumber (nums ) < 2360 ; 2 ;

                                         0

                                       ) ;

            charTest = Case ( lgthC > 0 and lgthC < 3 ; 1 ; 0 ) ;

            mins = Case ( lgthN > 2 ; Right ( nums ; 2 ) ; "00" ) ;

            hrs = Case ( lgthN > 2 ; Middle ( nums ; 1 ; lgthN - 2 ) ; nums ) ;

            hrsN = GetAsNumber ( hrs ) ;

            minsTest = Case ( GetAsNumber ( mins ) > 59 ; 0 ; 1 ) ;

            hrs12 = Case ( numTest = 2 ; GetAsText ( hrsN - 12 ) ;

                                     hrsN = 0 ; "12" ;

                                     hrs

                                  ) ;

            suffix = Case ( charTest = 1 and ( PatternCount ( chars ; "A" ) or Exact ( chars ; "M" ) ) ; " AM" ;

                                    charTest = 1 and ( PatternCount ( chars ; "P" ) or Exact ( chars ; "N" ) ) ; " PM" ;

                                    charTest = 0 and Exact ( Left ( nums ; 1 ) ; "0" ) ; " AM" ;

                                    numTest = 2 and hrsN > 12 ; " PM" ;

                                    ""

                                 ) ;

            hrsTest = Case ( GetAsNumber ( hrs12 ) > 12 ; 0 ; 1 ) ;

            suffixTest = Case ( hrsN > 12 and Exact ( suffix ; " AM" ) ; 0 ; 1 ) ;

            inter = GetAsNumber ( hrs12 & mins )

            ] ;

             

             

            Case ( numTest = 0 ; "INVALID TIME" ;

                        minsTest = 0 ; "INVALID TIME" ;

                        hrsTest = 0 ; "INVALID TIME" ;

                        suffixTest = 0 ; "INVALID TIME" ;

                        inter > 0 and inter < 700 ; Left ( inter ; 1 ) & ":" & Right ( inter ; 2 ) &

                                    If ( not IsEmpty ( suffix ) ; suffix ; " PM" ) ;

                        inter >= 700 and inter < 1000 ; Left ( inter ; 1 ) & ":" & Right ( inter ; 2 ) &

                                    If ( not IsEmpty ( suffix ) ; suffix ; " AM" ) ;

                        inter >= 1000 and inter < 1200 ; Left ( inter ; 2 ) & ":" & Right ( inter ; 2 ) &

                                    If ( not IsEmpty ( suffix ) ; suffix ; " AM" ) ;

                        inter >= 1200 and inter < 1260 ; Left ( inter ; 2 ) & ":" & Right ( inter ; 2 ) &

                                    If ( not IsEmpty ( suffix ) ; suffix ; " PM" ) ;

                        "INVALID TIME"

                    )

                )

             

            It's only the 'military' time that I'm interested in but I didn't dare strip out the rest...

             

            Thanks

            Brian.

            • 3. Re: Set Variable but format it at the same time?
              wimdecorte

              Not sure what's going on here but if you do this in your script it should work:

               

              set another variable to the result of the custom function: $cleanTime = parseTime ( $inputTime )

              then use Set Field to set the field to $cleanTime

              • 4. Re: Set Variable but format it at the same time?
                brian.curran

                Sorry, I'm a bit of a newbie at FM custom functions!

                How do I do the above? I'm fine with Set Variable and Set Field but the rest is completely beyond me...

                • 5. Re: Set Variable but format it at the same time?
                  brian.curran

                  Can anybody help with this? I'm stuck on the 'live' system now so could really do with working this issue out...

                   

                  Thanks

                  Brian.

                  • 6. Re: Set Variable but format it at the same time?
                    Mike_Mitchell

                    By default, a variable contains a text value. Try using GetAsTime ( ) when you insert the variable value into the field.

                     

                    Mike

                    • 7. Re: Set Variable but format it at the same time?
                      brian.curran

                      Hi Mike,

                      I'm struggling here, the 'time' data in my Hosted file works fine with the auto-enter calc but when I sync down to my Mobile file (using GoZync) the field shows a "?" despite having the same auto-enter calc in place.

                       

                      I think I read somewhere that the sync changes the Time to Text but I'm not sure where to insert "GetAsTime ()" to transform it back again. I also might have the same problem when syncing from my Mobile file up to the Hosted file...

                       

                      Thanks

                      Brian.

                      • 8. Re: Set Variable but format it at the same time?
                        brian.curran

                        Thanks both, I managed to work it out eventually.

                         

                        The layouts where we do the data entry on the Hosted and Mobile files need to have the auto-enter calc but the 'Sync' layouts on both files need to have it turned off. It's always the easy ones that take the longest to figure out

                         

                        Thanks again for your help...

                        Brian.