Page 1 of 1
Save data
Posted: Thu Feb 11, 2010 12:13 am
by ukaussie
I've read the tutorial on saving data (
http://www.revjournal.com/tutorials/sav ... ution.html), but i'm not sure where to put the code:
Code: Select all
put the filename of this stack into tPath
set the itemDelimiter to "/"
put "DateTime folder/" into last item of tPath
if there is not a folder tPath then create folder tPath
Code: Select all
put tTextData into URL ("file:" & tPath & "TextData")
Do i put these on the mainstack within an "on closeStack" command, or will the data be saved 'on the fly' rather than on exiting the application?
Second, the tutorial doesn't say how you then load the saved data into your application when it is next opened. How do you do this?
Cheers,
Grant.
Re: Save data
Posted: Thu Feb 11, 2010 3:05 am
by RRobert
You could put the lines into the closeStack- or mouseDown handler e.g. you use a Save button. And load the data via
Code: Select all
put URL ("file:" & tPath & "TextData") into tTextData
Robert
Re: Save data
Posted: Thu Feb 11, 2010 12:53 pm
by ukaussie
Hi Robert,
Thanks for that. I've created two scripts on the main stack. The first loads each file into its respective variable. If there is no folder (on first launch of the app) then the default value of the scrollbar is loaded into the variable. The second 'on closestack' script creates the folder and each of the files successfully, but does not save the value of the scrollbar. I've opened each of the files in the folder and the value stored is the default value rather than the value of the scrollbar at the time of exiting the application. Can you see why this might be happening?
Code: Select all
global tmRestingHR, tmMaximalHR, tmMeanHR, tmSessionDuration, tfRestingHR, tfMaximalHR, tfMeanHR, tfSessionDuration, tmTRIMPAnswer, tfTRIMPAnswer
on openstack
put URL ("file:" & tPath & "mRestingHR") into tmRestingHR
if there is not a folder tPath then put the thumbposition of scrollbar "Male Resting HR Slider" on card "Male" into tmRestingHR
put URL ("file:" & tPath & "fRestingHR") into tfRestingHR
if there is not a folder tPath then put the thumbposition of scrollbar "Female Resting HR Slider" on card "Female" into tfRestingHR
put URL ("file:" & tPath & "mMaximalHR") into tmMaximalHR
if there is not a folder tPath then put the thumbposition of scrollbar "Male Maximal HR Slider" on card "Male" into tmMaximalHR
put URL ("file:" & tPath & "fMaximalHR") into tfMaximalHR
if there is not a folder tPath then put the thumbposition of scrollbar "Female Maximal HR Slider" on card "Female" into tfMaximalHR
put URL ("file:" & tPath & "mMeanHR") into tmMeanHR
if there is not a folder tPath then put the thumbposition of scrollbar "Male Mean HR Slider" on card "Male" into tmMeanHR
put URL ("file:" & tPath & "fMeanHR") into tfMeanHR
if there is not a folder tPath then put the thumbposition of scrollbar "Female Mean HR Slider" on card "Female" into tfMeanHR
put URL ("file:" & tPath & "mSessionDuration") into tmSessionDuration
if there is not a folder tPath then put the thumbposition of scrollbar "Male Session Duration Slider" on card "Male" into tmSessionDuration
put URL ("file:" & tPath & "fSessionDuration") into tfSessionDuration
if there is not a folder tPath then put the thumbposition of scrollbar "Female Session Duration Slider" on card "Female" into tfSessionDuration
put URL ("file:" & tPath & "mAnswer") into field "mTRIMPAnswer" on card "Male"
if there is not a folder tPath then put 122 into field "mTRIMPAnswer" on card "Male"
put URL ("file:" & tPath & "fAnswer") into field "fTRIMPAnswer" on card "Female"
if there is not a folder tPath then put 116 into field "fTRIMPAnswer" on card "Female"
end openstack
on closestack
put the filename of this stack into tPath
set the itemDelimiter to "/"
put "TRIMP folder/" into last item of tPath
if there is not a folder tPath then create folder tPath
put tmRestingHR into URL ("file:" & tPath & "mRestingHR")
put tfRestingHR into URL ("file:" & tPath & "fRestingHR")
put tmMaximalHR into URL ("file:" & tPath & "mMaximalHR")
put tfMaximalHR into URL ("file:" & tPath & "fMaximalHR")
put tmMeanHR into URL ("file:" & tPath & "mMeanHR")
put tfMeanHR into URL ("file:" & tPath & "fMeanHR")
put tmSessionDuration into URL ("file:" & tPath & "mSessionDuration")
put tfSessionDuration into URL ("file:" & tPath & "fSessionDuration")
put tmTRIMPAnswer into URL ("file:" & tPath & "mAnswer")
put tfTRIMPAnswer into URL ("file:" & tPath & "fAnswer")
end closestack
Re: Save data
Posted: Thu Feb 11, 2010 1:20 pm
by Klaus
Hi Grant,
there is a typo in the scripts:
Should be "... OF card xyz..." you wrote "on card xyz"
But that does not explain why the correct value is not getting saved.
BUT "tPath" in not in the globals and not defind in the "openstack" handler!
Some useful hints:
1. "outsource" these handlers to the stack script!
Name them "readprefs" and "writeprefs" or whatever!
This way you can always call them when needed, know what I mean?
2. You may run into problems if the user of your app does not have admin rights, in that case the user may NOT write into the folder where the app resides!
Use these folder to store your prefs:
Mac: specialfolderpath("preferences")
Win:
1. specialfolderpath(26) = the current users "Application Data" folder
2. specialfolderpath(35) = ALL users "Application Data" folder
You are definitvely allowed to write in these folders!
Check "specialfolderpath()" in the docs (Rev dictionary) for more info.
Best
Klaus