6 Replies Latest reply on Jul 1, 2013 10:29 AM by deathrobot

    Is there a way to number list items when using the "List ( fieldname )" function, so this:...

    deathrobot

      Post

           Is there a way to number list items when using the "List ( fieldname )" function, so this:

           Substitute (
                List (
                     fieldname
                );
                "¶";
                ",  "
           )
            
           would return:
            
           1) value01,  2) value02,  3) value03,  etc.
            
           instead of just:
            
           value01,  value02,  value 03,  etc.
            
           Thanks

        • 1. Re: Is there a way to number list items when using the "List ( fieldname )" function, so this:...
          philmodjunk

               a script or custom function could loop through the members of this list to insert an item number an parenthesis. Creating/installing a custom function requires FIleMaker Advanced. Do you have advanced?

          • 3. Re: Is there a way to number list items when using the "List ( fieldname )" function, so this:...
            philmodjunk

                 //NumberedList ( TheList, k )
                 //
                 Let ( items = ValueCount ( TheList ) ;
                          k & ") " &
                          Case ( items < 2 ; TheList ;
                                     GetValue ( TheList ; 1 ) & ", " & NumberedList ( RightValues ( TheList ; items - 1 ) ; k + 1 )
                          ) // Case
                        ) // Let

                 Your initial function call would look like this:

                 NumberedList ( List ( RelatedTable::FIeld ) ; 1 )

            • 4. Re: Is there a way to number list items when using the "List ( fieldname )" function, so this:...
              deathrobot

                   Thanks very much, PhilModJunk. This is exactly what I needed! One note; I see that you're using a recursive function, but I still have trouble following how it's treated as a kind of loop. Any recommneations on sources for learning this in more detail?

                   Thank you,

                   Michael

              • 5. Re: Is there a way to number list items when using the "List ( fieldname )" function, so this:...
                philmodjunk

                     In this post I am referring to the "end point recursion" used in this custom function. The recursive function call is at the end of the code. More complex recursion can be set up that "branches" into different recursive calls...

                     I still remember the brain strain I encountered when I first studied recursive code as a Computer Science major many years ago. Recursion always has a kind of "smoke and mirrors" feel to it when you first try to understand the technique.

                     I finally became comfortable with it by taking one of my recursive code examples and "paper executing" the code, keeping written track of the values of the parameters passed with each function call on a piece of paper and the values then returned to the preceding function call. Once I used recursion to loop a few times through the code, I was able to see how each pass through the code passed new data to it that had been slightly simplified from the data in the previous pass. Eventually, the recursive loops simplify the data down to a single simple value with an obvious result and then this value is returned to the previous function call where the simplest value can be combined in some type of calculation with the "next simplest" data to get a result and then this is also returned to yet another preceding function call until you eventually the code works it's way back out to the original call and a final result is returned.

                     In the case of this function, it strips off the left most member of the list with each recursive call and passes that shortened list as the simplified parameter along with an incremented value for k. When it works it's way to the rightmost element of the original list, it has counted the number of items in the list and now puts that number with the ) character and returns the entire list of just that rightmost value. The preceding function call now has a result that it can use to return the last two elements with correct numbering and the process continues back out until the original function call has the value it needs to return the desired numbered list.

                • 6. Re: Is there a way to number list items when using the "List ( fieldname )" function, so this:...
                  deathrobot

                       PhilModJunk: Thanks very much for this thoughtful explanation. I will be trying your "on paper" suggestion; sounds like a great idea.

                       Michael