Newbie again

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
dhobbs
Posts: 24
Joined: Tue Dec 15, 2009 6:25 pm

Newbie again

Post by dhobbs » Sat Feb 09, 2019 2:24 pm

All I want to do is open a text file and display it in a text field, modify it, then save it again. I can use the Answer command, but that gives me the path. How do I get the contents of the file? I've used Live code a long time ago (RunRev era), but the new dictionary is perplexing to me, and I can't remember how I loaded, searched, edited, and saved the text file. Can someone point me in the right direction?

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

Re: Newbie again

Post by Klaus » Sat Feb 09, 2019 2:36 pm

Hi dhobbs,

Code: Select all

## Load file into field:
...
answer file "Select text file:"
put IT into tFile

## User CANCELled
if the result = "cancel" then
   exit to top
end if

## Load file into field:
put url("file:" & tFile) into fld "your field here..."
...

Code: Select all

## Save field content to file:
...
put specialfolderpath("desktop") & "/your file.txt" into tFile
put fld "your field here..." into url("file:" & tFile)
...
Best

Klaus

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Newbie again

Post by bogs » Sat Feb 09, 2019 2:43 pm

Code: Select all

## Save field content to file:
...
put specialfolderpath("desktop") & "/your file.txt" into tFile
put fld "your field here..." into url("file:" & tFile)
...
Just to prevent some possible confusion, Klaus is using a direct save to the desktop in the above code, if you wanted to save it elsewhere, you'd have to use 'answer folder', if you wanted to save it back to where it came from, you could make tFile a script local variable.

You could also use a combination of the above in an 'if/then' branch off.
Image

dhobbs
Posts: 24
Joined: Tue Dec 15, 2009 6:25 pm

Re: Newbie again

Post by dhobbs » Sat Feb 09, 2019 2:48 pm

Perfect, thanks.
I totally forgot about the url keyword. Not particularly intuitive.
Appreciate it...

Post Reply