Writing text to a new line

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
altamative131
Posts: 7
Joined: Mon Jan 13, 2014 6:57 pm

Writing text to a new line

Post by altamative131 » Thu Jan 23, 2014 4:43 pm

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

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Writing text to a new line

Post by Klaus » Thu Jan 23, 2014 4:48 pm

Hi altamative131,

1. welcome to the forum! :D

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 :D


Best

Klaus

altamative131
Posts: 7
Joined: Mon Jan 13, 2014 6:57 pm

Re: Writing text to a new line

Post by altamative131 » Thu Jan 23, 2014 4:50 pm

Yes, holy geez I was over thinking that entire thing. Thank you

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Writing text to a new line

Post by dunbarx » Thu Jan 23, 2014 5:06 pm

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

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Writing text to a new line

Post by Klaus » Thu Jan 23, 2014 5:42 pm

altamative131 wrote:Yes, holy geez I was over thinking that entire thing. Thank you
You'll surely have this feeling some more often in the future! :D

Think simple = Livecode!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Writing text to a new line

Post by FourthWorld » Thu Jan 23, 2014 5:45 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply