1 Reply Latest reply on May 10, 2006 6:09 AM by Dawntay

    Help needed saving text members to TAB delimited txt file

    f0ld Level 1
      I have 7 text memebrs each containing several lines of text that were pulled in and sorted from a TAB delimited text file.

      What I'd like to know is, is there any way to convert those text members back into the TAB delimited format from which they came? I'd like to be able to pull in the data, let it be edited to some extent, then saved back out..... and I'm not too sure how to go about it.

      Example of txt file:
      ID_No Name Age
      1 Phil 26
      2 Sam 34
      3 Mary 21

      They're then sorted in to text files of ID_No, Name, and Age, with the lists of the relevent items in each.




      Certain lines of these text members change, depending on what the user selects. I'd like to put these sections back in their original TAB delimited format, but with any changed data replacing the old, so next ime the app is opened the new data is pulled in from the txt file.

      I know I'm probably going about this the wrong way, but it's the only way I know so far lol
      Any ideas?
        • 1. Re: Help needed saving text members to TAB delimited txt file
          Dawntay Level 1
          global filex, idlst, namelst, agelst

          on readtabline (str)

          tmpstr = ""
          y = 1

          repeat with x = 1 to the number of chars in str do
          if str.char[x] = tab then

          case y of
          1 : idlst.add (tmpstr)
          2 : namelst.add (tmpstr)
          3 : agelst.add (tmpstr)
          end case

          tmpstr = ""
          y = y + 1

          tmpstr = tmpstr & str.char[x]
          end if
          end repeat
          agelst.add (tmpstr)

          on exitFrame me
          idlst = [] --set up some lists to hold that data we read in
          namelst = []
          agelst = []

          filex = new (xtra "fileio")
          filex.openfile ("t.txt", 1)

          indata = filex.readfile() -- read the data in


          filex = void

          repeat with x = 1 to the number of lines in indata do
          readtabline(indata.line[x]) --seprate it into its diffrent elements
          end repeat

          -- you now have your data sorted in to three list of id, age and name
          -- so you would now do what ever editing you wanted to do

          --now to write it out to a new file

          filex = new (xtra "fileio")
          filex.createfile (the moviepath & "tout.txt")
          filex.openfile (the moviepath & "tout.txt", 2)

          repeat with x = 1 to idlst.count() do
          filex.writestring (idlst[x] & tab & namelst[x] & tab & agelst[x] & return)
          end repeat



          I tested this on your exact scenario and it worked a brezze

          hope it helps