1 Reply Latest reply on Oct 19, 2011 8:09 PM by Mister MUX

    create lists on the fly from a field

    wfzen Level 1

      I have a text memeber with the following content. I'd like to convert the text in each line into its own global list that will be used in another place.

       

      rightAnsL1 = [1, 2, "text here"];

      rightAnsL2 = [1, 1, "none"];

      rightAnsL3 = [1, 1, "none"];

      rightAnsL4 = [2, 1, "none"];

      rightAnsL5 = [1, 1, "none"];

      rightAnsL6 = [2, 2, "text 2 here"];

       

       

      How can I create multiple lists based on a total number?

       

      e.g.

      repeat with i = 1 to totalIneOfAMember -- 6 in this case

      global "myList"&(i) = [] -- initialize and make them global

      -- text manipulate to get 1, 2, "text here" in the first line, etc.

      -- assign that string to myList1, myList2, etc. to the end

      end repeat

       

      How do I make that work?

       

      Thanks,

        • 1. Re: create lists on the fly from a field
          Mister MUX

          You don't need to create a separate global variables in cases like this. You can use a single list variable and add as many elements to the list as needed. Of course the list elements can be lists themselves (as is the case in your example).

           

          So all you really need now is an algorithm to parse the text of your member to extract the individual list. As long as your lines are always formatted in the manner of your example, this handler will do the trick.

           

          on createAnswerListFromTextMember textMember

            answerList = []

            numLines = textMember.line.count

            repeat with lineNum = 1 to numLines

              answerList.add(value(textMember.line[lineNum].char[14..textMember.line[lineNum].char.coun t-1]))

            end repeat

            return answerList

          end

           

          Now you can assign the return value of the handler to a global variable. For example, if the text member that has the data in it is called answerList

           

          myList = createAnswerListFromTextMember(member "answerList")

           

          Instead of myList1, you can use myList[1], myList[2], etc