Writing values to specific line of text file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 11
- Joined: Thu Aug 23, 2018 2:14 pm
Writing values to specific line of text file
Hi all,
I‘m looking for a way to write data into a text file. My app needs to have several fields for entering values. These values shall be written into a text file (sometimes all at the same time, but in rare cases also individually). Writing to a text file is not the problem, but I would like each field to be written into a specific line of the text file because on another occasion the data shall be read from that specific line. What‘s the „best“ way of doing this?
Thanks a lot for your help!
I‘m looking for a way to write data into a text file. My app needs to have several fields for entering values. These values shall be written into a text file (sometimes all at the same time, but in rare cases also individually). Writing to a text file is not the problem, but I would like each field to be written into a specific line of the text file because on another occasion the data shall be read from that specific line. What‘s the „best“ way of doing this?
Thanks a lot for your help!
Re: Writing values to specific line of text file
I do that a lot and find the easiest method is to
Read the txt file into a hidden field
then replace the line of the txt in the field
then save back.
This method has the advantage that for testing you can unhide the field and check whats going on.
Read the txt file into a hidden field
then replace the line of the txt in the field
then save back.
This method has the advantage that for testing you can unhide the field and check whats going on.
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search
Re: Writing values to specific line of text file
Hi Summertime01,
welcome to the forum!
Since this is Livecode, you can access the TXT file (even its content like LINE, WORD etc.) directly with:
...
put fld "user field 666" into line 10 of url("file:" & path_to_your_txt_file)
...
Cool, isn't it?
Best
Klaus
welcome to the forum!
Since this is Livecode, you can access the TXT file (even its content like LINE, WORD etc.) directly with:
...
put fld "user field 666" into line 10 of url("file:" & path_to_your_txt_file)
...
Cool, isn't it?
Best
Klaus
-
- Posts: 11
- Joined: Thu Aug 23, 2018 2:14 pm
Re: Writing values to specific line of text file
Thank you!
Klaus, I actually tried what you suggested yesterday and it didn't work. Must have made a different mistake there. Will check the script. Thanks.
Klaus, I actually tried what you suggested yesterday and it didn't work. Must have made a different mistake there. Will check the script. Thanks.
Re: Writing values to specific line of text file
You're welcome!
If you still have problem, please post the script(s) here and we will see what we can find.
If you still have problem, please post the script(s) here and we will see what we can find.
-
- Posts: 11
- Joined: Thu Aug 23, 2018 2:14 pm
Re: Writing values to specific line of text file
Thank you!
It works now. Had a file path issue in my script. Umpfm!
It works now. Had a file path issue in my script. Umpfm!
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Writing values to specific line of text file
Look more deeply into the "Chunk" stuff of LC.
Craig Newman
Code: Select all
on mouseup
get "Hello Wrld"
put "o" after char 1 of word 2 of it
answer it
get "Hello WXrld"
put "o" into char 2 of word 2 of it
answer it
end mouseup