Writing values to specific line of text file

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Summertime01
Posts: 11
Joined: Thu Aug 23, 2018 2:14 pm

Writing values to specific line of text file

Post by Summertime01 » Fri Aug 24, 2018 8:51 am

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!

AndyP
Posts: 451
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Writing values to specific line of text file

Post by AndyP » Fri Aug 24, 2018 9:34 am

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.
Andy Piddock

http://2108.co.uk/tinyide/ - Mini LC IDE alternative

http://2108.co.uk/script-editor-themer/ - Script Editor colour theming

http://livecodeshare.runrev.com/stack/897/LiveCode-Multi-Search - Search across 8 LC resources

Klaus
Posts: 11313
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Writing values to specific line of text file

Post by Klaus » Fri Aug 24, 2018 9:37 am

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


Best

Klaus

Summertime01
Posts: 11
Joined: Thu Aug 23, 2018 2:14 pm

Re: Writing values to specific line of text file

Post by Summertime01 » Fri Aug 24, 2018 9:42 am

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
Posts: 11313
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Writing values to specific line of text file

Post by Klaus » Fri Aug 24, 2018 9:48 am

You're welcome!

If you still have problem, please post the script(s) here and we will see what we can find.

Summertime01
Posts: 11
Joined: Thu Aug 23, 2018 2:14 pm

Re: Writing values to specific line of text file

Post by Summertime01 » Fri Aug 24, 2018 11:05 am

Thank you! :-)

It works now. Had a file path issue in my script. Umpfm!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6258
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Writing values to specific line of text file

Post by dunbarx » Fri Aug 24, 2018 10:09 pm

Look more deeply into the "Chunk" stuff of LC.

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
Craig Newman

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”