File Read/Write

André Rombauts andre.rombauts at skynet.be
Fri Jan 21 11:47:35 CST 2005


Strange (to me): when using the write & read to file the position for
reading starts at 1.When using the 'open for update' I have to set it to 0
otherwise data cannot be written properly. Is this normal?

Andre Rombauts
 
on mouseUp

put 1 into rec
open file "test.txt" for binary write
repeat 3 times
write "Line " & rec to file "test.txt"
put rec + 1 into rec
end repeat
close file "test.txt"

put 1 into rpos
open file "test.txt" for binary read
repeat 3 times
put (rpos * 6) - 5 into readpos
read from file "test.txt" at readpos for 6 chars
put "[" & it & "]" after display
put rpos + 1 into rpos
end repeat
close file "test.txt"
put display into field "Log"

put 1 into wpos
open file "test.txt" for binary update
repeat 3 times
put (wpos * 6) - 6 into writepos
write "Sign " & wpos to file "test.txt" at writepos
put wpos + 1 into wpos
end repeat
close file "test.txt"

put 1 into rpos
open file "test.txt" for binary read
repeat 3 times
put (rpos * 6) - 5 into readpos
read from file "test.txt" at readpos for 6 chars
put "[" & it & "]" after display
put rpos + 1 into rpos
end repeat
close file "test.txt"
put display into field "Log" 

end mouseUp




More information about the use-livecode mailing list