6 Replies Latest reply on Dec 18, 2013 1:51 PM by NicholasFernandez

    Setting a $variable array to a list of strings

    NicholasFernandez

      Title

      Setting a $variable array to a list of strings

      Post

           Hi,

           I want to initialize a $variable array from a predetermined list of strings so that I can use a loop to search for each string and then replace a field in the found records with a value from a second variable array. I have been able to create arrays by having FileMaker pull the values from fields, but what if I want to pass in a separate set of values that will not already exist in the database?

           (for example: $myArray = "one", "two", "cat", "dog")

           and using another table to store the array is not an option. 

           Thanks for your help!

           Nick

        • 1. Re: Setting a $variable array to a list of strings
          philmodjunk

               I wouldn't use an array for that. Use a list of return separated values.

               Set Variable [$TheList ; value: List ( "one", "two", "cat", "dog" ) ]

               Then you can use the getValue function to reference specific values in that list. GetValue ( $TheList ; 1 ) returns "one" in this example.

          • 2. Re: Setting a $variable array to a list of strings
            NicholasFernandez

                 Hi Phil,

                  

                 That made sense, but when I pass the variable to a Perform Find, it is searching for a literal: "GetValue (one, two, cat, dog)." The same problem persists if I remove "GetValue," only without the "GetValue" part of the text in the search. The problem also exists if I remove the $i variable and use a constant as well (see below). Thanks for any advice. 

                 Here's what I'm doing.

                 Set Variable [$TheList; value: List ("one", "two", "cat", "dog")]

                 Set Variable [$TheListReplace; value: List ("one for me", "two for you", "black cat", "red dog")]

                 Set Variable [$i; Value: 1]

                 Loop

                      Perform Find[] (set field "Source" to "GetValue($TheList; $i)

                      Replace Field Contents (set field "Source" to "GetValue($TheListReplace; $i)

                      Set Variable [$i; Value: $i + 1]

                      Exit Loop if [GetValue($TheList; $i) = 0]

            • 3. Re: Setting a $variable array to a list of strings
              philmodjunk

                   You can't use an expression inside stored find criteria.

                   Enter find mode, use set field to set a field to the specified criteria then perform the find.

                   See this thread for examples of this method: Scripted Find Examples

              • 4. Re: Setting a $variable array to a list of strings
                NicholasFernandez

                     Hi Phil,

                     I see. I tried the following, but something is still amiss. (and I read through the link).

                     If it's simple, can you tell me what I would put in the blank below using one of my variables/lists

                     Program:

                       
                •           Set all variables
                •      
                •           Enter Find
                •      
                •           Set field (set field "Source" to _______________)

                     Do I need to pass my list to another variable? I've tried different combinations and can't get it to work (even though I've had success with another script using a values list derived from a field). Sorry to trouble you.

                      

                      

                      

                • 5. Re: Setting a $variable array to a list of strings
                  philmodjunk

                       The devil can be in the details. Your set field should have this exact format, but with your names in place of mine for the table, field and variable:

                       Set Field [YourTable::Field ; GetValue ( $VariableList ; 1 ) ]

                       but since you have multiple values, it should be inside a loop if you want to search for all the listed values:

                       Loop
                          Set Variable [$K ; Value: $K + 1 ]
                          Set Field [YourTable::Field ; GetValue ( $VariableList ; $K ) ]
                          Exit Loop IF [ $K > ValueCount ( $VariableList ) ]
                          New Record/Request
                       End Loop
                       Set Error Capture [on]
                       Perform Find []

                  • 6. Re: Setting a $variable array to a list of strings
                    NicholasFernandez

                         well, I actually did want it outside of the loop, but I had a typo in my variable name...

                         Sorry! Great help otherwise :)

                         now the last step of my loop isn't functioning, but I'll figure that part out.

                         Thanks!