Page 1 of 1
Saving text from text field to .txt file
Posted: Mon Oct 22, 2012 10:17 pm
by rvolpe
It used to be very easy to save text from a text field to an external .txt file, but on LiveCode I cannot figure out how to do this. I am a beginning coder, but use livecode to create academic interventions for kindergarten children. I have created a standalone app and I want to be able to keep the data I am collecting in a text field in the app, but each time I quit the app it dumps the data. It would be easy if I could just have a button for the users to click on to save a text file at the end of each session. I would appreciate any help you might offer.
Thank you in advance for your time- I know I must sound like a total noob.
Re: Saving text from text field to .txt file
Posted: Mon Oct 22, 2012 10:29 pm
by mwieder
I know I must sound like a total noob.
Not at all - the syntax for this isn't quite as straightforward as some other things in the language.
For a standalone app, if you want to save the text file in the same folder as the app you can just say
Code: Select all
put field "theTextFieldWithTheDataToSave" into url ("file:myTextFile.txt")
If you want to get more complicated, you can set the defaultFolder to somewhere else, or specify a path instead of hard-coding "myTextFile.txt"
Re: Saving text from text field to .txt file
Posted: Fri Nov 02, 2012 3:28 pm
by japino
rvolpe wrote:I want to be able to keep the data I am collecting in a text field in the app, but each time I quit the app it dumps the data.
I'm a beginner too, but one I learned is that you can do this: create a mainstack that serves as a splash screen, and then create a substack for your main application. Any changes to your main application can be saved within the application if you put this into your stack script:
Code: Select all
on closeStack
save this stack
pass closeStack
end closeStack
Re: Saving text from text field to .txt file
Posted: Fri Nov 02, 2012 3:44 pm
by FourthWorld
japino wrote:rvolpe wrote:Any changes to your main application can be saved within the application...
...provided you've set the filename property of the stack being saved to a writable location.
Keep in mind that most OSes won't allow writes to the location where the app is stored, so you'll want to move any savable elements to user-writable folders.