Read from file, then display results
Mark Brownell
gizmotron at earthlink.net
Thu Jul 8 00:53:12 EDT 2004
on 7/7/04 7:30 PM, Marian Petrides at mpetrides at earthlink.net wrote:
> 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?
yours:
put it into AddListContents
split AddListContents by tab
repeat with j = 1 to 6
put AddListContents[j] into line j of field "Results"
end repeat
mine:
put it into AddListContents
set the itemDelimiter to tab
put 1 into thisSpot
repeat for each item j in AddListContents
put j into line thisSpot of field "Results"
add 1 to thisSpot
end repeat
> 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
try this:
on mouseUp
global gFilePath
answer file "select a file"
if it contains ".txt" then
put URL ("file:" & it) into AddListContents
put it into gFilePath
else
answer " Not a text file"
exit mouseUp
end if
end mouseUp
-- work from the variable AddListContents
-- after all work is done to your var then save it using this:
on mouseUp
global gFilePath
put compress(AddListContents) into URL ("binfile:" & gFilePath)
-- now your file is compressed
-- to open and decompress it use:
-- put decompress(URL ("binfile:" & it)) into AddListContents
-- for none compression save:
-- put AddListContents into URL ("file:" & gFilePath)
end mousUp
hope this helped some,
Mark
More information about the use-livecode
mailing list