4 Replies Latest reply on Jan 25, 2011 8:35 PM by ColinChandler

    Variables: How to assign variables to calculated field names



      Variables: How to assign variables to calculated field names


      Hi – I am a relative newb, so please forgive if this is a complex approach to a simple problem, in FM 11.0v2

      I am attempting to set up a table that will receive downloaded data from a barcode scanner.

      I have a table of 150 global fields to accept the incoming data. Table – “Barcode” which has global fields “Line”

      So far so good.

      Now I need a script to take each value from each field and convert it to a variable I can use in a variety of functions on 3 other tables. The names of the variables need to incrementally increase as well, of course.

      This would give a list of unique variables that correspond to each field in the “barcode’ table.

      My issues fall into 2 parts

      1. Navigation to fields; I thought perhaps this aproach would work

      Set Variable [$Num; Value:1] #Num is my line counter

      Set Variable [$Name; Value:”Barcode::”&”Line”&$Num]

      Now I need to get to the $Name field...Go to Field would be just lovely – ‘cept it doesn’t take variables as its direction...

      I could instead use Go to field and then, Go to next field - just seems a bit fragile...

      2. I need the value of the field the script has arrived at to be set as a variable - with a variable title

      The logical approach seems to use Get (ActiveFieldContents)

      Eg - Set Variable [“Line”&$Num; Get(ActiveFieldContents)

      But of course that wont work as an identifier

      *It works to manually Set Variable [$$Line1; Value:Barcode::Line1] , then line2, Line 3 etc – but with a possible 150 entries, this is very inelegant (as I found noted on various other threads!)

      I am hoping that someone may be able to point out something bleedingly obvious as a change of approach? Or to point to a thread I have missed on the topic ...

      Thanx in advance

        • 1. Re: Variables: How to assign variables to calculated field names

          It's maybe just as inelegant as your 'manual' solution, but if you named the fields as objects, the 'Go To Object' can be directed by an incremented variable.  I recognise you will have to name 150 objects

          • 2. Re: Variables: How to assign variables to calculated field names

            Thanks for taking a look at the problem Sorbsbuster, that does seem to be the only way - though as far as I can see, I'll still need an approach to store each line as a unique variable. Which means also writing the name for each field manually too...and which seems unnecassarily cumbersome..

            I am working through learning how to get the field name and use it as a $$name for the contained data, and I cant help but feel that this could be the answer for directing to a field as well. Any suggestions much appreciated!


            • 3. Re: Variables: How to assign variables to calculated field names

              Well, I have a big leap forward: I found thesupportgroup.com had worked around a similar problem - and with loads of effort I now have a script to write variables based on the name of the field - which actually works so far! With some exit lop paramaters etc I should have what I needed for the variables.

              Now to see if I can use the same approach for navigation to each field...if my forehead can stand it...running out of bandaids...

              Heres the script for any interested:

              Set Variable [$n; Value:0]


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

              Set Variable [$varName; Value:”$$Line” & Right (“0” & $n;2)

              Set Variable [$varValue; Value: Get(ActiveFieldContents)]

              Set Variable [$setNameandValue; Value:Let (  [variableName = $varName ; variableValue = $varValue ; formula = "Let ( variableName = variableValue ; \"\" )" ] ; Evaluate ( Substitute ( formula ;[ "variableName" ; variableName ] ; [ "variableValue" ; Quote(variableValue) ] )  //close Substitute )  // close Evaluate)  //close Let

              Go to Next Field

              End Loop

              Cool hey - (well to the filemaker newbs like me..)?!

              • 4. Re: Variables: How to assign variables to calculated field names

                Having jumped in the deep end of the Filemaker pool, the sharks have begun circling!

                In the above script I now have a list of incrementally named variables with values, however I am now stuck on parsing the values incrementally to the sort section of the database...

                I thought I had a handle on the $setnameandvalue variable script step, but cant get my head around how to step through it again without changing the contents of each variable.

                I should also point out I am guessing a lot of how many of the functions actually operate, so feel free to point out the whole approach is daft

                Any thoughts would help preserve what little remains of my sanity.....if there ever was any.....