4 Replies Latest reply on Apr 9, 2013 12:50 AM by davehob

    Repeating variables - non-numeric repetition no.

    davehob

      Just discovering the joys of “bucket variables”, I’ve realised that it’s possible to use non-numeric values in the repetition number, as long as I use quotes around the repetition ‘number’ when referencing it . For example, if I want to record a value for a record whose key value is a unique serial prefixed with “PPL”, I can set the variable thus;

       

      Set variable [$$Test[PPL_kp_id]; Value:”xxxxx”]

       

      and I can then reference it thus;

       

      $$Test[“PPL123”]

       

      The alternative seems to be to strip out the (unique) numerical part of the key and use that as the repetition number, but I just wondered whether using the whole thing has any pitfalls or downsides?

       

      Dave.

        • 1. Re: Repeating variables - non-numeric repetition no.
          mikebeargie

          I'd recommend sticking with whatever key structure is familiar to you (and any other developers accessing the system). I guess the only downfall would be "forgetting" the correct reference later on when you are using it.

           

          If you strip out the prefix, it could cause confusion down the line when you are troubleshooting in the data viewer (assuming you have other table prefixes, like COM123, ADD123, etc..)

           

          Another pitfall would be not being able to use it for virtual lists effectively. If you have a "report" table that is pulling from a $$data variable to display a virtual list, then it makes sense to increment it on serial numbers starting from 1.

           

          Usually when I'm using $$data variables for virtual lists (running through a list of records to generate a variable stored list, then parsing/accessing it later), I am generating unique serials for the list values each time (IE 1,2,3,4,etc..). This makes it easy for me on the other end to know I'm always starting with 1, and ending with whatever Get(FoundCount) was for the amount of records in my list.

          1 of 1 people found this helpful
          • 2. Re: Repeating variables - non-numeric repetition no.
            wimdecorte

            the easiest solution to this is to turn the string into numbers using the code() function.

             

            $$test[code("ppl123")]

             

            Otherwise you are forcing FM to cast your string as a number and you may not always get a unique repetition.

            • 3. Re: Repeating variables - non-numeric repetition no.
              BruceRobertson

              "I’ve realised that it’s possible to use non-numeric values in the repetition number, as long as I use quotes around the repetition ‘number’ when referencing it . "

               

              No, it is in fact not possible.

               

              Turning the rep into an integer is not just the easiest thing; it's the only thing that actually works.

               

              Wim's suggested way of getting an integer result for a string by using the code() function works fine.

               

              The rep is an integer; period.

               

              For instance what is the result of this statement:

               

              Let([

              $$total["cat"] = 3;

              $$total["dog"]=45;

              report_line = "Pet placements this month are " & $$total["cat"] & " cats and " & $$total["dog"] & " dogs."

              ];

              report_line

              )

               

              Answer:

              The statement above does not declare two different variables.

              It declares ONE variable, with the ending value defined by the last declaration.

              Since getAsNumber( "cat") returns an empty result; and getAsNumber( "dog") returns an empty result; the numeric value is zero.

               

              $$total[0] value: 45

               

              So the report statement result would be:

              "Pet placements this month are 45 cats and 45 dogs."

               

              Likewise,

               

              Let([

              $$total["cat2"] = 3;

              $$total["dog2"]=45

              ];

              ""

              )

               

              Result:

              $$total[2], value: 45

               

              If you tried this:

              List( $$total["cat2"]; $$total["dog2"])

              You would get

              45

              45

              1 of 1 people found this helpful
              • 4. Re: Repeating variables - non-numeric repetition no.
                davehob

                Such helpful replies.  Here's a summary, as I understand it.  Using the key value "as is" would be "OK" in this situation, where the key value used for the repetition number contains a unique numerical portion, and where I just need to reference the value later on.  But using the code function to convert that key value to an integer reduces the potential for error, and is clearly the right way to do it.  (Although a non-unique repetition number would break it, whether it's originally text or originally integer.)

                 

                Thanks again for the help.

                 

                Dave.