13 Replies Latest reply on Apr 5, 2013 1:21 AM by Fimano

    Navigation needing calc to restore last used tab

    Fimano

      I have a good and working system for navigation in my solution. In a global var ($$currentTabObjectName), it stores which tab [object name] was selected, triggered by OnTabSwitch. However, this object name (like tab_address) is only unique per module, so in my module called STU (with student records), there is a tab_address pane, but in the UNI module (with records for universities), there might be a tab with the same name. This is allowed by FMP and I do not want to force myself to name the tabs differently. So in essence, if I was at the tab_address pane in STU, the system currently would 'think' I should return to tab_address in both STU and UNI, even if my last selected tab pane in UNI was tab_document.

       

      OK, so much for the background. I am wanting a calculation to determine if a list contains a string (that part I can easily do) and if so, this string's entire line/value should be removed and replaced with a new one. An example could clear things up:

      --

      STU--tab_address

      UNI--tab_document

      INT--tab_equipment

      CON--tab_address

      --

      could be my desired list of "tabs where the current user left the module". Now, if they went to STU and selected the "tab_document" tab, the list should be still 4 lines/values, but the 1st value should change.

       

      What would the smart calculation be like?

        • 1. Re: Navigation needing calc to restore last used tab
          BruceHerbach

          I would assume that the layouts are based on different tables.  So use the layout table to determine the left side of the string.

           

          HTH

          Bruce

          • 2. Re: Navigation needing calc to restore last used tab
            Fimano

            No problem, I am already doing this. But the thing is that I get multiple lines per module, which is unwanted.

            I.e.

             

            STU--tab_address

            UNI--tab_document

            CON--tab_address

            STU--tab_document

            • 3. Re: Navigation needing calc to restore last used tab
              Mike_Mitchell

              Would there be anything wrong with using an array?

               

              $$currentTabObjectName[0] = STU--tab_address

              $$currentTabObjectName[1] = UNI--tab_document

              $$currentTabObjectName[2] = CON--tab_address

              etc.

               

              Then you just replace the appropriate repetition with the new value.

               

              Mike

              • 4. Re: Navigation needing calc to restore last used tab
                DavidJondreau

                "Module" isn't a well-defined term here, but let's assume you're talking about layouts.

                 

                I handle this with a coded repeitition:

                 

                $$tab.Name [ Code ( Get ( LayoutName ) ) ]

                • 5. Re: Navigation needing calc to restore last used tab
                  steve_ssh

                  Hello Fimano,

                   

                  How about something like the calculation below?

                   

                  ( Swap in values for varList, varSearchString, and varReplaceString. )

                   

                  HTH & Best,

                   

                  -steve

                   

                   

                   

                  Let([

                   

                      // Input

                   

                      varList = "";

                   

                      varSearchString = "";

                     

                      varReplaceString = "";

                     

                   

                   

                      // Config

                     

                      DELIMITER = Char( 13 );

                     

                      ADD_TO_LIST_IF_NO_MATCH = True;

                         

                   

                    

                     // Calculation

                   

                      varListLength = Length( varList );

                     

                      varReplaceString = Case( IsEmpty( varSearchString ); ""; varReplaceString );

                     

                      varReplaceExists = not IsEmpty( varReplaceString );

                   

                      varFirstPosition = Position( varList; varSearchString; 0; 1 );

                     

                      varDelimiterCount = PatternCount( Left( varList; varFirstPosition ); DELIMITER );

                     

                      varIndex01 = Position( varList; DELIMITER; 0; varDelimiterCount );

                     

                      varIndex02 = Position( varList; DELIMITER; varIndex01 + 1; 1 );

                     

                      varLeftChars = Case( varFirstPosition; varIndex01 - ( varDelimiterCount > 0 ); varListLength );

                     

                      varRightChars = Case( varFirstPosition and varIndex02; varListLength - varIndex02; 0 );

                     

                      varDelimiter01 = Case( varLeftChars and varReplaceExists; DELIMITER );

                     

                      varDelimiter02 = Case( varRightChars and varReplaceExists; DELIMITER; not varReplaceExists and varLeftChars and varRightChars; DELIMITER )

                     

                  ];   

                      

                      Left( varList; varLeftChars ) &  Case( varFirstPosition or ADD_TO_LIST_IF_NO_MATCH; varDelimiter01 & varReplaceString ) & varDelimiter02 & Right( varList; varRightChars )   

                  )

                  • 6. Re: Navigation needing calc to restore last used tab
                    Fimano

                    @Mike:

                    Thank you for the suggestion. An array with the repetition numbers you mention would suggest a field. It is too static for my purpose. I do not want to maintain the number of repetitions when a new module gets added. But it could work, surely.

                    • 7. Re: Navigation needing calc to restore last used tab
                      Fimano

                      @David:

                      Sorry about the undefined module term. Module, in my book, is 1 or more layouts, typically a form/detail and a list + possibly various printouts. So it is a logical part of the system. Often, it corresponds roughly to a TOG. It is what I use to communicate to the users which parts the systems consists of. In this case, I even use my internal 3-letter TOG name in the documentation, which I co-write with a power user.

                      I am not sure about what you mean by coded repetition?

                      • 8. Re: Navigation needing calc to restore last used tab
                        Fimano

                        Steve, thank you very much. I don't quite get the results I expected, though.

                         

                        In the meantime, I got a PM with a great solution:

                        1: Create a new Custom Function, call it something like "ReplacePrefixedString"

                        2: Add a parameter called "prefix"   (important!)

                        3: Add a parameter called "value"   (important!)

                        4: Add a parameter called "listOfValues"     (important!)

                        5: Copy and paste the following calculation to the custom functions calculation part

                         

                         

                        Let([

                         

                        exist = PatternCount (  "¶" & listOfValues  ; "¶" & prefix ) > 0;

                         

                        start = Position ( "¶" & listOfValues ; "¶" & prefix ; 0 ; 1 ) + 1;

                        stop = Position ( "¶" & listOfValues & "¶" ; "¶" ; start ; 1 );

                         

                        newList = Replace ( "¶" & listOfValues & "¶" ; start ; stop - start ; prefix & value );

                        newList = Left( newList; Length(newList) - 1 );

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

                         

                        ];

                         

                        If( exist; newList; listOfValues & If( Length(listOfValues) > 0; "¶"; "" ) & prefix & value )

                         

                        )

                         

                         

                         

                        What this does is that it finds the first value in listOfValues that has the given prefix and replaces that value withvalue. If no prefix is found the value will simply be added at the end of the list.

                         

                        It is important that listOfValues does NOT begin or end with a linebreak! Always use this calculation for this specific task and you should be fine!

                         

                         

                        Example:

                         

                        ReplacePrefixedString( "STU--"; "tab_document"; "STU--tab_addressUNI--tab_documentINT--tab_equipmentCON--tab_address" )

                         

                        This will replace STU--tab_address with STU--tab_document. Note that the prefix is added automaticly to the added value!

                        It does exactly what I was looking for.

                         

                        I think this discussion could be used for stating 'best practice methods' of restoring tab selection? I have played with saving a found set too, both with and without use of FileMaker Snapshot Link. But that discussion is a little off topic, I guess.

                        • 9. Re: Navigation needing calc to restore last used tab
                          debi

                          Fimano,

                           

                          This does not directly answer your question about your calculation, but you may find this useful for the same end result:

                          http://jonathanstark.com/blog/using-script-triggers-to-restore-active-tabs-in-filemaker

                          Works in v11 and v12.

                           

                          Debi Rubel

                          FullCity Consulting

                          • 10. Re: Navigation needing calc to restore last used tab
                            Mike_Mitchell

                            Well, no, you can do the same thing with a variable. Doesn't have to be part of the schema; I don't know if that makes it dynamic enough for you.

                             

                            Mike

                            • 11. Re: Navigation needing calc to restore last used tab
                              DavidJondreau

                              Variables have repetitions. They're not as robust as true arrays but it's what FileMaker's got.

                               

                              Mike's example is to us repetitions like:

                              $$variable[0]

                              $$variable[1]

                               

                              My suggestion is similar, but instead of assigning a number to a module, you can use the Code() function to convert a text string (e.g. a layout name) into a number.

                               

                              So a variable encoding would be $$variable[ Code ( Get ( LayoutName ) ) ] and the actual variable may look like this: $$variable[81212010120312301024102312031203103101]

                               

                              It's the most flexible way to handle this. The only "hardcoded" piece is the name of the variable, like $$tab.name. Everything else is dynamic and can be applied to any solution.

                              • 12. Re: Navigation needing calc to restore last used tab
                                steve_ssh

                                Hello Fimano,

                                 

                                I'm glad that you have found a solution that works well for you.

                                 

                                Best,

                                 

                                -steve