Saving user modifications to Table Data

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

trags3
Posts: 432
Joined: Wed Apr 09, 2014 1:58 am

Re: Saving user modifications to Table Data

Post by trags3 » Fri May 02, 2014 10:05 pm

magice wrote:In the standalone application settings, go to the stacks tab. Hit the add stack file button and choose you stack. This will include that stack with your stand alone app.
OK. I can test the app on my phone which is connected to the Mac workbook pro that I am working on. It all compiles right installs on the phone and runs. When I get to the 2 places in the app where the external table is referenced the program just hangs. It works fine in the IDE.
From the main menu when I push a button to go into one branch of the program I want to load the saved data int the fields in the app for display on the screen.
The code is as follows:

On mouseUp
go to stack "agentdata" # AgentData is the external stack with 1 card and the table with my custom properties.
put the agentname of fld "tagentinfo" into fld "aname" of card 5 of stack "JATY" # tagentinfo is the table field name JATY is the Root program

etc.
close stack "AgentData"
go to card 2 of stack "JATY"
end mouseUp

See any problems?
I don't have the comments in the actual prog file.
Tom

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Saving user modifications to Table Data

Post by Simon » Fri May 02, 2014 11:23 pm

Hi Tom,
I actually think you have to save the data stack using the "Copy Files" tab in the standalone builder, then to actually save to it copy it from the "engine" to "documents".

There is a bunch of short hand in there, if not clear just say.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

trags3
Posts: 432
Joined: Wed Apr 09, 2014 1:58 am

Re: Saving user modifications to Table Data

Post by trags3 » Fri May 02, 2014 11:55 pm

Simon wrote:Hi Tom,
I actually think you have to save the data stack using the "Copy Files" tab in the standalone builder, then to actually save to it copy it from the "engine" to "documents".

There is a bunch of short hand in there, if not clear just say.

Simon
Hi Simon,
What is the engine?
BTW this is an app for android if that makes a difference.

Tom

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Saving user modifications to Table Data

Post by Simon » Sat May 03, 2014 12:07 am

Hi Tom,
Look up specialFolderPath() in the dictionary.
Files that are copied with your stack end up in the specialFolderPath "engine", you can read from there but you cannot write to there so you have to do the extra step of copying the file from "engine" to specialFoderPath "documents". And yes this is true for Android.

Make sense?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

trags3
Posts: 432
Joined: Wed Apr 09, 2014 1:58 am

Re: Saving user modifications to Table Data

Post by trags3 » Sat May 03, 2014 12:12 am

Thanks Simon,
I think I got it.
Can I do that with the file browser on the mac with the phone connected?
or should I write a script to do it and run it on the phone?

Tom

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Saving user modifications to Table Data

Post by Simon » Sat May 03, 2014 12:31 am

Hi Tom,
It must be done by script for the mobile device.
put url(specialFolderPath("engine") && "/myStack.livecode") into url(specialFolderPath("documents") && "/myStack.livecode")

Actually in liveCode one should never say "must"...

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

trags3
Posts: 432
Joined: Wed Apr 09, 2014 1:58 am

Re: Saving user modifications to Table Data

Post by trags3 » Sat May 03, 2014 1:04 am

Hi Simon
I guess i'll move on to the next problem. I only have a couple more to conquer for this app.
I put the following into a button script.


put url(specialFolderPath("engine") && "/AgentData.livecode") into url(specialFolderPath("documents") && "/AgentData.livecode")

It still doesnt work. :(

I really appreciate your help.
Hopefully the summer school will do me some good.

Thanks Again.
Tom

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Saving user modifications to Table Data

Post by Simon » Sat May 03, 2014 1:06 am

Sorry it just hit me that that was missing something :)

put url("binfile:" & specialFolderPath("engine") && "/AgentData.livecode") into url("binfile:" & specialFolderPath("documents") && "/AgentData.livecode")

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

trags3
Posts: 432
Joined: Wed Apr 09, 2014 1:58 am

Re: Saving user modifications to Table Data

Post by trags3 » Sat May 03, 2014 1:57 am

Hi Simon,
I tried the statement as you sent it and with "&&" instead of "&" after "binfile:".
neither worked.

i'm moving on from this one for now.
The effort hasn't been a waste of time as I have learned quite a bit with each difficulty I encounter. :)
Thanks again for your support.

Tom

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Saving user modifications to Table Data

Post by Simon » Sat May 03, 2014 2:15 am

Hi TOm,
I'm very sorry about giving you the run around
Here it is:

Code: Select all

 put url ("binfile:" & specialFolderPath("engine") & "/AgentData.livecode") into \
            url ("binfile:" & specialFolderPath("documents") & "/AgentData.livecode")
&& creates a space and that is not right.

I promise to double check my answers. :(

Make sure AgentData.livecode is in the "Copy Files" and named that (I messed up once and wasted a day because I misspelt the name)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

trags3
Posts: 432
Joined: Wed Apr 09, 2014 1:58 am

Re: Saving user modifications to Table Data

Post by trags3 » Tue May 13, 2014 4:34 am

Simon wrote:Hi Tom,
Here is the lesson on it:
http://lessons.runrev.com/s/lessons/m/4 ... pplication

I actually prefer to use a plain text file as it's easy to open and read but a stack can hold binary data (images).

(if Craig is right then don't read this post)
Doh! :)

Simon
Simon, I have tried the Plain Text file approach and I have so far been unable to make it work. I want to open a text file and write 5 lines of information in it.
1st line: Name
2nd line Company
3rd line Cell#
4th Line Office #
5th line email address.

When the stack is opened I want to read these items from the text file and store them in 5 fields on a card.
If any of those things change over time the user can go to that card and edit the fields and save them back into the text file.
Here is the code for a button I use to write the edited changes to the text file:

on mouseUp
put specialFolderPath("documents" & "/tagent.txt") into tfile
put fld "Aname" into tvar
put tvar into line 1 of tfile
put fld "Aoffice" into tvar
put tvar into line 2 of tfile
etc
go card 1
end mouseUp


When I open the stack I try to open the tagent.txt file with this code:

on openStack

go card 5 # the card where I keep the data when the app is running or when I edit it.
put specialFolderPath("documents" & "/tagent.txt") into tfile
open file tfile
put line 1 of tfile into fld "Aname"
put line 2 of tfile into fld "Aoffice"

etc.
close file tfile
go card 1

end openStack

When I close the program ans reopen it the fields on card 5 are empty.

I know it must be something small.
BTW this is an Android app.

Thanks
Tom

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Saving user modifications to Table Data

Post by Simon » Tue May 13, 2014 4:51 am

Hi Tom,
I've been posting this a bunch
http://forums.runrev.com/phpBB2/viewtop ... ce#p103136
Grab that myPlants stack.
Study where I put the files and after you have added some images and descriptions look at the Preference.txt file. (Watch out large images >5mb take a while to load). A lot of the code in it is really only used once to create a new file.
Everything is there to show you how to create your own preference file.

If you get stuck just ask :)

Simon
Edit: OK a bit more info just in case I'm being a smarty pants. The text file will be save in a subfolder of your Documents folder "myPlants" and I use tab as an item delimeter (note: set itemDel to tab). The stack works correctly on the desktop and mobile.
Edit 2: I didn't plan for returns (cr, crlf etc.) in the description field... it may break on that.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

trags3
Posts: 432
Joined: Wed Apr 09, 2014 1:58 am

Re: Saving user modifications to Table Data

Post by trags3 » Wed May 14, 2014 6:51 pm

Simon wrote:Hi Tom,
I've been posting this a bunch
http://forums.runrev.com/phpBB2/viewtop ... ce#p103136
Grab that myPlants stack.
Study where I put the files and after you have added some images and descriptions look at the Preference.txt file. (Watch out large images >5mb take a while to load). A lot of the code in it is really only used once to create a new file.
Everything is there to show you how to create your own preference file.

If you get stuck just ask :)

Simon
Edit: OK a bit more info just in case I'm being a smarty pants. The text file will be save in a subfolder of your Documents folder "myPlants" and I use tab as an item delimeter (note: set itemDel to tab). The stack works correctly on the desktop and mobile.
Edit 2: I didn't plan for returns (cr, crlf etc.) in the description field... it may break on that.
Simon,
I don't need images so I have tried to delete all image related code fro your Myplants stack.
I only need 5 text lines of code and never more than that. I have assumed (probably naively) that a simple text file can be used for this purpose.
Here is the code for the card that attempts to implement this:

on preOpenCard
--check to make sure your folder exists
if there is not a directory (specialFolderPath("documents") & "/sellnet") then
create folder (specialFolderPath("documents") & "/sellnet")
else
end if
set the defaultFolder to (specialFolderPath("documents") & "/sellnet")
--load your Preference file into memory
put url("file:tAgent.txt") into tfile
end preOpenCard

on openCard
set itemDel to tab
if tfile <> empty then
-- this will tell us to load the last image into this cd
#put the number of lines of gPref into gCount I left this out because there there only needs to be 1 page.
put line 1 of tfile into fld "Aname"
put line 2 of tfile into fld "Aoffice"
put line 3 of tfile into fld "Acell"
put line 4 of tfile into fld "officep"
put line 5 of tfile into fld "Aemail"
else
end if
if fld "begin" of card 1 ="T"
then
put "F" into fld "begin" of card 1
go card 1
end if
end openCard

The begin fld on card 1 is a flag I set.
When the app is first started it = "T" and on open card 1 is sent to this card to populate the 5 fields on card 5 with the stored values in the text file.
there is a button on card 1 that sends the user to card 5 allowing them to edit or enter the data in the fields.
In this case after entering all data there is a "Finished" button with the following code:
on mouseUp
put fld "Aname" into tvar
put tvar into line 1 of tfile
put fld "Aoffice" into tvar
put tvar into line 2 of tfile
put fld "acell" into tvar
put tvar into line 3 of tfile
put fld "officep" into tvar
put tvar into line 4 of tfile
put fld "Aemail" into tvar
put tvar into line 5 of tfile
go card 1
end mouseUp

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Saving user modifications to Table Data

Post by Simon » Wed May 14, 2014 8:07 pm

Hi Tom,
5 lines of text is certainly possible.
I am a bit confused with your post... is there a question you have? Is the code you posted not working? I'd like to know before I sit down to review it.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

trags3
Posts: 432
Joined: Wed Apr 09, 2014 1:58 am

Re: Saving user modifications to Table Data

Post by trags3 » Wed May 14, 2014 8:14 pm

Simon wrote:Hi Tom,
5 lines of text is certainly possible.
I am a bit confused with your post... is there a question you have? Is the code you posted not working? I'd like to know before I sit down to review it.

Simon
Hi Simon, No absolutely not working. When I go to card 5 the Aname field is populated with the word "tfile" and all others are blank
I knoe there is something easy here but I can't find it.
BTW I have tested with and without the "set itemDel to tab" line with no difference.

Thanks
Tom
Simon, I changed the Finished button code to:
on mouseUp
put fld "Aname" & cr & fld "Aoffice" & cr & fld "acell" & cr & "Officep" & cr & "Aemail" & cr into tfile
put tfile into url("file:" & (specialFolderPath("documents") & "/sellnet/tagent.txt"))
go card 1
end mouseUp

simpler but still doesn't work.

Tom
Last edited by trags3 on Thu May 15, 2014 5:24 pm, edited 1 time in total.

Post Reply