3 Replies Latest reply on Oct 30, 2006 1:59 PM by Garek007

    Need to take an item from a list and make it the name of a new list.

    Garek007 Level 1
      My code is below. I am trying to taka a list, take the first item in that list as a text string, and use that word to create a new list with the same name. A code snippet of what I most recently tried is below. please help
      prods = [:]
      test = [:]
      repeat with lineNum in recordTextLines
      recordData = split(lineNum,tab)

      -- pop the first two items from the front of the list
      -- which are the 'cat' and 'prod' values:

      recordData[1] = [:]
      --formerly cat = recordData[1]


      -- test[#bldgName] = recordData[2]
      -- test[#bldgAddress] = recordData[3]
      -- test[#bldgArea] = recordData[4]
      -- test[#bldgUses] = recordData[5]
      -- test[#bldgNumFloors] = recordData[6]
      -- test[#bldgHeight] = recordData[7]
      -- test[#bldgYear] = recordData[8]
      -- test[#bldgExt] = recordData[9]
      -- test[#bldgUBC] = recordData[10]

      --value(recordData[1]) = test
        • 1. Need to take an item from a list and make it the name of a new list.
          duckets Level 1
          While it's possible to do this (create arbitrarily named variables on the fly) using director's "do" command, I would advise against it. It almost always leads to poorly structured code when better options exist.

          Might I suggest creating a property list to contain your 'created lists'. Perhaps if you describe more clearly what it is you want to end up with, someone could provide some suggestion as to how to achieve it.

          As far as I can see, your unique identifying field is 'cat' (presumably 'catalog number?'). If this is the case, perhaps you should create a property list called products, within which you can place each new property for each record:

          products = [:]

          ...then, within the loop through each record, build a new property list:

          thisRecord = [:]
          thisRecord[#cat] = recordData[1]
          thisRecord[#bldgName] = recordData[2]
          thisRecord[#bldgAddress] = recordData[3]
          thisRecord[#bldgArea] = recordData[4]
          thisRecord[#bldgUses] = recordData[5]
          thisRecord[#bldgNumFloors] = recordData[6]
          thisRecord[#bldgHeight] = recordData[7]
          thisRecord[#bldgYear] = recordData[8]
          thisRecord[#bldgExt] = recordData[9]
          thisRecord[#bldgUBC] = recordData[10]

          ...and add it to the 'products' proplist, using its own 'cat' value (presuming that is the unique record ID) as the property name:

          products[thisRecord.cat] = thisRecord

          You should end up with a property list called 'products', from which you can retrieve any product, by referring to its 'cat':

          put products["2264"] (assuming there was a record with "2264" as its 'cat')

          This method is using strings for the property names in the 'products' proplist, because as I recall your 'cat' values are 4 digit numbers.

          Hope this helps!

          - Ben

          • 2. Re: Need to take an item from a list and make it the name of a new list.
            Garek007 Level 1

            That solution sounds good I am going to explore that. I don't have categories, I just took this code form someone in this forum and have yet to change the variable names to more appropriate things.

            I have buildings with building numbers. What would work for me is to have one list that contains a property list for each building. The property list would then contain:

            bldgNumber: 2280
            bldgName: Library
            bldgSqFootage: 20,000

            and so forth.
            • 3. Re: Need to take an item from a list and make it the name of a new list.
              Garek007 Level 1

              Your suggestion worked very well, thank you so much. It is exactly what I needed.