Read from file, then display results?

Marian Petrides mpetrides at earthlink.net
Thu Jul 8 00:35:41 EDT 2004


Okay.  I played around some more and found that if I capture the entire 
file into a single variable AddListContents (as set forth in my 
original message) and then

   Set the itemDelimiter to tab
	put the number of items in AddListContents into tItemNum

	split AddListContents by tab
      --must split after determine number of items, not before

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

I get the result I was looking for.

Is this the best way to do it?

Is there any way to do it by capturing the data directly into the array 
rather than reading it into AddListContents and then extracting it from 
there?

M


On Jul 7, 2004, at 10:30 PM, Marian Petrides wrote:

> 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
>
>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>


More information about the use-livecode mailing list