Writing text to a new line
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 7
- Joined: Mon Jan 13, 2014 6:57 pm
Writing text to a new line
I am trying to export data and add to an existing text file. I do not know how to get Livecode to start on the next line, instead of replacing the current text in the file.
Basically here is what I am doing. I have Info.txt that has data in it already, I am just trying to add to it in after the existing info.
Any help would be much appreciated.
Thanks
Basically here is what I am doing. I have Info.txt that has data in it already, I am just trying to add to it in after the existing info.
Any help would be much appreciated.
Thanks
Re: Writing text to a new line
Hi altamative131,
1. welcome to the forum!
2. You can use FILES must like Livecode fields!
Like this:
...
put specialfolderpath("desktop") & "/Info.txt" into tFile
## TText conatins any text you want to append:
## Write NEW LINE and the text AFTER the file:
put CR & tTExt AFTER url("file:" & tFile)
...
## To insert BEFORE any other text
...
put tText & CR BEFORE url("file:" & tFile)
...
## Even this:
put tText into word 3 of line 4 of url("file:" & tFile)
...
You get the picture
Best
Klaus
1. welcome to the forum!

2. You can use FILES must like Livecode fields!
Like this:
...
put specialfolderpath("desktop") & "/Info.txt" into tFile
## TText conatins any text you want to append:
## Write NEW LINE and the text AFTER the file:
put CR & tTExt AFTER url("file:" & tFile)
...
## To insert BEFORE any other text
...
put tText & CR BEFORE url("file:" & tFile)
...
## Even this:
put tText into word 3 of line 4 of url("file:" & tFile)
...
You get the picture

Best
Klaus
-
- Posts: 7
- Joined: Mon Jan 13, 2014 6:57 pm
Re: Writing text to a new line
Yes, holy geez I was over thinking that entire thing. Thank you
Re: Writing text to a new line
Another method, and I post it here just so you get a clearer picture of how LC handles what it calls "chunking", would be something like:
put newText into line (the number of lines of oldText +1) of oldtext
So if oldText had 30 lines, the newText would start at line 31. No need for CR thinking.
This has benefits in certain cases.
Craig Newman
put newText into line (the number of lines of oldText +1) of oldtext
So if oldText had 30 lines, the newText would start at line 31. No need for CR thinking.
This has benefits in certain cases.
Craig Newman
Re: Writing text to a new line
You'll surely have this feeling some more often in the future!altamative131 wrote:Yes, holy geez I was over thinking that entire thing. Thank you

Think simple = Livecode!
-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Writing text to a new line
LiveCode's "open file" command allows many options, including "update", "read", "write", and "append". The "append" option will automatically write to the end of the file.
In addition to being convenient, it's also very efficient for that specific task since it doesn't need to also read the file contents. For small files the performance gain won't matter much, but with large files it can make a noticeable difference.
See the Dictionary entry for the "open file" command for details.
In addition to being convenient, it's also very efficient for that specific task since it doesn't need to also read the file contents. For small files the performance gain won't matter much, but with large files it can make a noticeable difference.
See the Dictionary entry for the "open file" command for details.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn