Read from file, then display results

Marian Petrides mpetrides at earthlink.net
Wed Jul 7 22:30:15 EDT 2004


I am having trouble displaying text read from a file.

I have two fields per card, one for name, one for address.  I write the 
contents of these six fields (2 per card) to a file, separated by a 
comma thusly:

   Open file "AddressList.txt" for write
   Repeat with j = 1 to the number of cards

     go to cd j
     --if simply use repeat for the number of cards, will start save on 
whatever is current card
     write field "WhatName" to file "AddressList.txt"
     write tab to file "AddressList.txt"
     write field "WhatAddress" to file "AddressList.txt"
     write tab to file "AddressList.txt"

     go next cd
   end Repeat

   Close file "AddressList.txt"

No problem.

I can open the file and read from it thusly:

   Open file "AddressList.txt" for read

   Read from file "AddressList.txt" until EOF
   Put it into AddListContents
   Close file "AddressList.txt"

Again no problem


I can   even         split AddListContents by tab

No problem.  And I can even display the resultant items line by line in 
a field without a problem so long as I specify a fixed number of 
iterations for the repeat loop:

repeat with j = 1 to 6
    put AddListContents[j] into line j of field "Results"
  end repeat

I have two questions:

1)  What I would like to be able to do is:

Figure out a more general way to specify number of iterations for the 
repeat  (something like:  repeat with j = 1 to the number of words in 
file "AddressList.txt"

How do I do this?

2) In a similar vein, is there a way to break the data up into items as 
it is being read.  I think I can probably use   "read from file until 
tab"

What I can't figure out is how to set up a loop that will read from the 
file until a tab is encountered, put the data into AddListContents[j]  
then go on and read the next item.

Again, I think the stumbling block is the syntax which will tell the 
loop to repeat until it reaches the end of the file.  Eg,

Repeat with j = 1 to  <what do I put here>
read from file until tab
<how do I tell it I want to read from the last tab until the next tab>
end repeat

TIA.

M





More information about the use-livecode mailing list