Saving text from text field to .txt 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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
rvolpe
Posts: 1
Joined: Mon Oct 22, 2012 10:11 pm

Saving text from text field to .txt file

Post by rvolpe » Mon Oct 22, 2012 10:17 pm

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.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Saving text from text field to .txt file

Post by mwieder » Mon Oct 22, 2012 10:29 pm

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"

japino
Posts: 78
Joined: Sun Oct 14, 2012 10:56 am

Re: Saving text from text field to .txt file

Post by japino » Fri Nov 02, 2012 3:28 pm

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

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

Re: Saving text from text field to .txt file

Post by FourthWorld » Fri Nov 02, 2012 3:44 pm

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

Post Reply