open file for text read

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

open file for text read

Post by zaxos » Tue Aug 26, 2014 8:54 pm

hello ppl, i have a text file that gets data from a shell every second, in livecode i use open file for text read and then read from file until eof, the problem is that eventualy the file gets too large and livecode takes too much time to read it, the questing: is there a way to keep track of the last position read from was at ? or there any way at all to speed up the procesing time of the text if it gets too large?
Knowledge is meant to be shared.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: open file for text read

Post by Simon » Tue Aug 26, 2014 10:58 pm

"read from file" in the dictionary suggests there is a start character and an end character.
So you'd just track those.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

Re: open file for text read

Post by zaxos » Tue Aug 26, 2014 11:10 pm

Hey there simon, thank you for your time helping.
I'm assuming that you mean i should use a buffer with the characters every time i read from the file, well i'v tryied this and its just as slow as reading the whole file, basicly the code takes some numbers from the txt and adds them then it puts them in a var, what i want is to add the numbers then put them in the var and the next time it reads from the txt it should only add the lines added to the txt, not all of it...
if i misunderstood your suggestion let me know :)
Knowledge is meant to be shared.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: open file for text read

Post by Simon » Tue Aug 26, 2014 11:58 pm

this seems to do it:

Code: Select all

global tCount
on mouseUp
   set the defaultFolder to specialFolderPath("desktop")
   open file "temp.txt" for read
   read from file "temp.txt" at tCount until EOF
   put it
   put the (number of chars of it + 1) into tCount
   if tCount = 1 then put 0 into tCount
   close file "temp.txt"
end mouseUp
but it's sloppy. Not sure if there is any more speed.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply