9 Replies Latest reply on Sep 23, 2014 9:06 PM by smith7180

    Null Values in Lists Vs. Carriage separated strings

    smith7180

      I adopted Lists() early on as my preferred method for passing multiple parameters. However, I'm increasingly dissatisfied with the inability to pass null "" paramters. So I tried ditching the list function and simply using carriage returns.

       

      This:

      tableA::Field_1 & ¶ &

      tableA::Field_2 & ¶ &

      tableA::Field_3

       

      As opposed to thisL

      List (

      tableA::Field_1;

      tableA::Field_2;

      tableA::Field_3

      )

       

      I just succesfully tried a quick test script on the first method. Simply passed 5 fields as parameters. 1 and 5 had values A and B. 2-4 had no value. Script just displayed message:

      "P1 =" & GetValue ( Get ( ScriptParameter ); 1) & ¶ &

      "P2 =" & GetValue ( Get ( ScriptParameter ); 2)& ¶ &

      "P3 =" & GetValue ( Get ( ScriptParameter ); 3)& ¶ &

      "P4 =" & GetValue ( Get ( ScriptParameter ); 4)& ¶ &

      "P5 =" & GetValue ( Get ( ScriptParameter ); 5)

       

      The script displayed:

      P1 = A

      P2 =

      P3 =

      P4 =

      P5 = B

       

      Am I missing something? Does manually constructing a list using "¶ " get you all the benefits of a regular list plus the ability to have null parameters?

       

      Edit: I only posted this after I felt like I had sufficiently googled the issue. Of course as soon as I post I find this tidbit from Jeremy Bante on the fmforums: "The difference between the two is that concatenating returns will preserve empty values."

       

      Still I wonder though- is that all? Is there any catch or dangers to manually constucting a list?

       

      Thanks.

        • 1. Re: Null Values in Lists Vs. Carriage separated strings
          jbante

          Is there any chance I could persuade you to use name-value pairs?

          1 of 1 people found this helpful
          • 2. Re: Null Values in Lists Vs. Carriage separated strings
            TomHays

            smith7180 wrote:

             

            Does manually constructing a list using "¶ " get you all the benefits of a regular list plus the ability to have null parameters?

             

            Edit:  I only posted this after I felt like I had sufficiently googled the issue.  Of course as soon as I post I find this tidbit from Jeremy Bante on the fmforums: "The difference between the two is that concatenating returns will preserve empty values."

             

            Still I wonder though- is that all?  Is there any catch or dangers to manually constucting a list?

             

             

             

            That is all. There are no hidden gotchas.

             

            The List() function is designed to separate all non-empty arguments with "¶".

            Concatenating directly using "¶" will allow you to include all values including empty ones.

             

            -Tom

            • 3. Re: Null Values in Lists Vs. Carriage separated strings
              smith7180

              I'm certainly willing to try anything suggested by someone from posts (on various forums) have been so helpful...

               

              ...(several hours later)...

               

              I hope I'm using it right (full disclosure- I'm a noob.  ~4 months filemaker expereince, no prior programming expereince).  Pardon the basic questions, but is this the idea?

               

              parameters like so:

              # ( "first" ; TableA::FieldA)  &  # ( "second" ; TableA::FieldB) & ...

               

              Script step like so:

              set variable [$dictionary //I assume it doesn't matter what I call the variable? ; Value: #Assign (Get ( ScriptParameter ))

               

              Now refer to paramters as local variables:

              SetField [TableB::FieldA; $first]

               

              Thanks!

               

              Edit: Wow- so you can see all your parameters in the data viewer this way.  That's really helpful I think!

              • 4. Re: Null Values in Lists Vs. Carriage separated strings
                Mike_Mitchell

                Still I wonder though- is that all?  Is there any catch or dangers to manually constucting a list?

                 

                Yes, the most obvious of which is, "What happens if one of your parameters contains a carriage return?"

                 

                Oops. The entire scheme blows up, which is why name/value pairing is generally preferred (and why Jeremy recommended it). You can get around it by substituting another string for the carriage return (such as "<cr>" or <\n\r>" - something unlikely to appear in the actual data), then substituting it back in when you extract the parameter. However ... why bother when there's a better method?

                 

                Mike

                • 5. Re: Null Values in Lists Vs. Carriage separated strings
                  smith7180

                  Thanks Mike.

                   

                  I certainly wouldn't defend my method (regarding carriage returns I either quote or get the field name (and then getfield in script)).  However with a program like filemaker in which users are often learning as they develop (with no aspirations for more 'serious' strains of programming), one inevitably runs into the issues of refining vs replacing imperfect techniques.

                   

                  My decision to initally use lists instead of name-value pairs was made when I was especially green.  I simply didn't understand name-value pairs.  Even now, it took me a while to succesfuly implement Jeremy's custom funtion.  I had no idea how to use github.  Figuring out I needed #() & #assign(), and that #assign() had to be used in a set variable step wasn't easy.

                   

                  I mean, I'm glad it wasn't easy- I learned a lot.  However taking a path of lesser resistance is not necessarily the wrong decision in light of other constraints and goals.  Though I certainly get that on the technet forums one should assume the advice one recieves is the optimal advice, and I totally respect that.

                   

                  I'm reminded of city planning where aiming for the ideal can be disasterous to one's schedule/budget (especially when it involves midcourse changes/revisions (like replacing all my parameters)).

                   

                  Whatever route I take, I hugely appreciate the time taken by more experienced developers to reply to less experienced users like myself.

                  • 6. Re: Null Values in Lists Vs. Carriage separated strings
                    Mike_Mitchell

                    You asked. I answered.  

                    • 7. Re: Null Values in Lists Vs. Carriage separated strings
                      smith7180

                      With regards to name-value pairs, specifically jbante's wonderful #() custom function, can one pass a text formatted value?  I'm having a hard time getting this to work correctly:

                       

                      # ( "value_1" ;  TextStyleAdd ( "Terms and Conditions"; Bold))

                       

                      I don't want to add the TextStyle in the script because I'm looping through fields and values and only some value have text styles:


                      Set Field By Name (Evaluate ( "$field_"  & $counter )) ; Evaluate ( "$value_"  & $counter )

                       

                      Thanks!

                       

                      Edit: For now I've added "TextStyleAddBold" to the value and modified the scripts Set Field By Name like as follows, but I'd still love to know how to pass TextStyles through name-value pairs.

                       

                      Let ( $val = Evaluate ( "$value_"  & $counter );

                                Case (

                                          LeftWords ($val ; 1) = "TextStyleAddBold"; TextStyleAdd ( RightWords($val ; WordCount ($val ) - 1 ) ; Bold );

                                          $val

                                 )

                      )

                      • 8. Re: Null Values in Lists Vs. Carriage separated strings
                        jbante

                        The custom functions do not currently support text styles in parameters. It's not a need that many developers request. If you are going to stick with just what those custom functions I liked to give you, then I recommend that you pass the style as a separate parameter from the text content. And if you have to pass a list of similar values to iterate over, I recommend you consider the #Array function:

                         

                        #Array ( "fieldName" ; 1 ; GetFieldName ( Table::field1 ) )

                        & #Array ( "value" ; 1 ; "value one" )

                        & #Array ( "format" ; 1 ; Bold )

                        & #Array ( "fieldName" ; 2 ; GetFieldName ( Table::field2 ) )

                        & #Array ( "value" ; 2 ; "value two" )

                        & #Array ( "format" ; 2 ; Plain )

                        // etc.

                         

                        Then you could write this in your script:

                         

                        Set Field By Name [$fieldName[$i]; TextStyleAdd ( $value[$i] ; $format[$i] )]

                         

                        If you're willing to get your hands dirty with the Let Notation that the #parameters functions work with, then it is possible to include style as part of a parameter more directly by wrapping the quoted text of a parameter value with the functions that will style it when passed through the #Assign function:

                         

                        "$value = TextStyleAdd ( "

                        & Quote ( $textToStyle )

                        & " ; Bold ) ;¶"

                        1 of 1 people found this helpful
                        • 9. Re: Null Values in Lists Vs. Carriage separated strings
                          smith7180

                          This is perfect thank you.   You have persuaded me. The script steps and the parameters are so much clearer (and fewer) this way.


                          I don't understand why $value[$i] worked but $format[$i] did not work (ie the $value was not formatted) until I nested $format[$i] in an evaluate function.