4 Replies Latest reply on Aug 4, 2006 12:30 PM by Newsgroup_User

    Using lists and fileio

    Shellgrip
      I hope I haven't missed the solution to this in searching, I apologise if I have.

      I'm saving some basic user details from my projector (DMX 2004, PC) using fileio and the saving bit works fine. What I was aiming to do was construct a list and then put this out to a file, so.

      pDetails = ["Forename", "Surname"] -- and so on
      userdets = new (xtra "fileio")
      setFilterMask (userdets,"Text Files, *.txt")
      filename = userdets.displaySave("Save your details to...", "userdets.txt")
      createfile (userdets, filename)
      openfile (userdets, filename, 2)
      writeString (userdets, string(pDetails))
      userdets.closeFile()

      This works fine - examining the saved text file it contains ["Forename", "Surname"] (obviously this data is actually provided from text input). However, when I try and read the file in, Director treats it as a string and encloses the whole thing in quotes so in

      pDetails = userdets.readFile()

      pDetails comes in as "["Forename", "Surname"]" which I then can't read as a list.

      So... is there either a readfile method that specifies the data is a list, or is there a better way to store this data full stop? I'm able to get it working by simply storing a string using delimiters (i.e. the saved file contains just Forename, Surname and is brought in as "Forename, Surname") but I'd really like to use a list so I can make it a property list in the final version.

      Am I making any sense? :)

      Jon
        • 1. Re: Using lists and fileio
          Shellgrip Level 1
          Sigh... once again, I've posted, then found the (obvious) answer.

          value()

          taking the literal value of the read string so it can be assigned to the list properly. All working now. Hopefully my stupidity will help someone else.

          J
          • 2. Re: Using lists and fileio
            Level 7
            The best solution is to store each item in your list as a separate line
            in the text file. This will get you around the list in a string dilemma.

            Try this:

            pDetails = ["Forename", "Surname"] -- and so on
            totalItems = pDetails.count
            repeat with i = 1 to totalItems
            myString = myString & pDetails & RETURN
            end repeat
            delete myString.line[myString.line.count]
            userdets = new (xtra "fileio")
            setFilterMask (userdets,"Text Files, *.txt")
            filename = userdets.displaySave("Save your details to...",
            "userdets.txt")
            createfile (userdets, filename)
            openfile (userdets, filename, 2)
            writeString (userdets, myString)
            userdets.closeFile()

            Then to get your data back, do something like this:

            pDetails = userdets.readFile()
            tempList = []
            totalLines = pDetails.line.count
            repeat with n = 1 to totalLines
            if value(pDetails.line[n]) = VOID then
            totalLines.add(pDetails.line[n])
            else
            totalLines.add(value(pDetails.line[n]))
            end if
            end repeat
            pDetails = tempList

            --
            Rob
            _______
            Rob Dillon
            Adobe Community Expert
            http://www.ddg-designs.com
            412-243-9119

            http://www.macromedia.com/software/trial/
            • 3. Re: Using lists and fileio
              Shellgrip Level 1
              Thanks for taking the time to post that Rob, it'll prove useful.

              I've another tricky bit to navigate past coming up but I promise to try harder before posting :)

              Jon
              • 4. Re: Using lists and fileio
                Level 7
                An alternative is to use the free functions of vList xtra to save to an
                external file in native list format. It's much faster than FileIO,
                doesn't require 'value()' conversion and can save native Director data
                types.
                <http:/www.updatestage.com/xtras/vlist.html>