Page 1 of 2
check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 12:26 pm
by keram
Hello,
The stack that I made should display the text line categories. I can set the Categories on the Select Categories card and the settings are saved in an external text file. When opening the stack again the Categories are correctly displayed in the form but on the card where the selection is made the selected check boxes do not correspond to the displayed Categories.
The code on the stack level that is not working for the above:
Code: Select all
global gAllLines,gSelectedCategories
on openStack
put empty into gAllLines
set the itemDelimiter to tab
put fld "alllines" of cd "settingsandfiles" into gAllLines
put empty into gSelectedCategories
set the itemDelimiter to tab -- do I have to set the itemDelimiter here again even though it was set above?
set the defaultFolder to specialFolderPath("Documents")
put URL ("file:./myAppsData.txt") into gSelectedCategories
if "s" is among the items of gSelectedCategories then set the hilite of btn "Short" of cd "select_categories" to true
if "m" is among the items of gSelectedCategories then set the hilite of btn "Medium" of cd "select_categories" to true
if "l" is among the items of gSelectedCategories then set the hilite of btn "Long" of cd "select_categories" to true
end openStack
The code on the Save button on the Select the Categories card is:
Code: Select all
global gAllLines,gSelectedCategories,gMyCategories
on mouseUp
put empty into gSelectedCategories
set the itemDelimiter to tab
if the hilite of btn "Short" is true then put "s" & tab after gSelectedCategories
if the hilite of btn "Medium" is true then put "m" & tab after gSelectedCategories
if the hilite of btn "Long" is true then put "l" & tab after gSelectedCategories
set the defaultFolder to specialFolderPath("Documents")
put gSelectedCategories into URL ("file:./myAppsData.txt")
go back
end mouseUp
The stack is attached
I'll appreciate any help to fix it.
Thanks in advance.
keram
Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 12:41 pm
by dave.kilroy
Hi Keram
I've just replied to your posting on StackExchange - this is what I wrote...
Keram, OK if your text file is in the right place and contains good content lets investigate elsewhere. Try inserting "Answer gSelectedCategories" in your openStack handler to see what is being returned from the text file, if you get nothing then the path to the file is wrong or perhaps you mistyped the name of your global variable. If the correct data appears in your answer dialoge then the problem is 'downstream' - insert an 'answer' or a 'put' in relevant parts of the code until you get something that doesn't work, then back up a bit and you will have found your problem! Good luck!
Kind regards
Dave
Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 4:23 pm
by keram
I've been doing just that - inserting 'answer gSelectedCategories' after Saving the text file and after loading it into the gSelectedCategories variable and it shows correct categories delimited by tabs. Also the data text file that is saved shows correct categories delimited by tabs.
keram
Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 4:29 pm
by dave.kilroy
OK it sounds like you are inserting the 'answer' code in the script of the 'save' button - I'm talking about inserting it in the openStack handler of the stack - so that it fires as the stack opens and you - at that stage - find out what the app knows...
Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 4:41 pm
by Klaus
Hi keram,
set the itemDelimiter to tab -- do I have to set the itemDelimiter here again even though it was set above?
No need to set it again beacuse it did not change in the meantime
And you do not need to set the itemdelimiter at all in the script of the SAVE button!
Hint:
Why mess around with the "defaultfolder", when you can have correct absolute pathnames?
...
### set the defaultFolder to specialFolderPath("Documents")
### put URL ("file:./myAppsData.txt") into gSelectedCategories
put URL ("file:" & specialFolderPath("Documents") & "/myAppsData.txt") into gSelectedCategories
...
### set the defaultFolder to specialFolderPath("Documents")
### put gSelectedCategories into URL ("file:./myAppsData.txt")
put gSelectedCategories into URL ("file:" & specialFolderPath("Documents") & "/myAppsData.txt")
...
That's even less typing!
Best
Klaus
Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 4:45 pm
by dave.kilroy
Quite agree Klaus - although elegant code might follow after Keram has found out what has gone wrong - can you give him some great debugging advice?
Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 4:50 pm
by keram
dave.kilroy wrote:OK it sounds like you are inserting the 'answer' code in the script of the 'save' button - I'm talking about inserting it in the openStack handler of the stack - so that it fires as the stack opens and you - at that stage - find out what the app knows...
Yes, that's what i've been doing as well and it shows correct categories when it opens.
keram
Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 5:03 pm
by keram
Klaus wrote:Hint:
Why mess around with the "defaultfolder", when you can have correct absolute pathnames?
Thanks Klaus, I've changed it - always good to learn new tricks. But the problem persists...
keram
Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 5:04 pm
by Klaus
Just tested your stack and it does what it is supposed to!?

Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 5:09 pm
by dave.kilroy
Hmm strange - I''ve just gone through your stack and can't get it to fail (on a mac)...
Could you try changing the name of the text file? I'm wondering if maybe you have another copy of the file somewhere on your system that your code is reading...
If that doesn't work then set a breakpoint in your openstack handler and watch what happens (should have said that to you much earlier)...
Good luck!
Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 5:12 pm
by dave.kilroy
Ah just read that Klaus's script worked! ...well done Klaus - now to figure out what made the difference...
Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 5:19 pm
by keram
Klaus wrote:Just tested your stack and it does what it is supposed to!?

Hmmm... strange! You mean that the checkboxes on the Select the Categories card correspond to the categories in the form after you have reopened the stack?
In any case, I made now the necessary changes that fixed the problem on my computer (it's PC):
the code under the stack is now this:
Code: Select all
on openStack
put empty into gAllLines
set the itemDelimiter to tab
put fld "alllines" of cd "settingsandfiles" into gAllLines
put empty into gSelectedCategories
put URL ("file:" & specialFolderPath("Documents") & "/myAppsData.txt") into gSelectedCategories
if "s" is among the items of gSelectedCategories then set the hilite of btn "Short" of cd "select_categories" to true
else set the hilite of btn "Short" of cd "select_categories" to false
if "m" is among the items of gSelectedCategories then set the hilite of btn "Medium" of cd "select_categories" to true
else set the hilite of btn "Medium" of cd "select_categories" to false
if "l" is among the items of gSelectedCategories then set the hilite of btn "Long" of cd "select_categories" to true
else set the hilite of btn "Long" of cd "select_categories" to false
end openStack
and I've tested it 10 times and it works
Thanks Dave and Klaus anyway for your attention and help.
keram
Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 5:35 pm
by Klaus
Hi keram,
great!
HInt: You should check, if htat file is already PRESENT in teh docs folder!
If not, then the script will halt at this point in a standalone!
but since your "prefs" file only conatins up to 3 cahracters you could even make it shorter
and by using BOOLEan values in a clever way you can even make the script shorter.
Code: Select all
on openStack
put empty into gAllLines
put fld "alllines" of cd "settingsandfiles" into gAllLines
## ALWAYS check, you are the developer and will have to take cares of these things!
## if the user fucks up, it is ALWAYS YOUR FAULT! :-D
put specialFolderPath("Documents") & "/myAppsData.txt" into tPrefs
if there is NOT file tPrefs then
exit openstack
end if
put empty into gSelectedCategories
put URL ("file:" & tPrefs) into gSelectedCategories
## Now a clever way to use a BOOLEan value, which can be TRUE or FALSE
## Heavy stuff, but please take the time to fully understand what I am writing,
## it will surely help you to write efficient code in the future!
## This will take care of correct de-/hiliting of your checkboxes!
set the hilite of btn "Short" of cd "select_categories" to (gSelectedCategories contains "s")
set the hilite of btn "Medium" of cd "select_categories" to (gSelectedCategories contains "m")
set the hilite of btn "Long" of cd "select_categories" to (gSelectedCategories contains "l")
end openStack
Best
Klaus
Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 5:36 pm
by dave.kilroy
Hi Keram
Aha! (on two counts)
Firsly - that it was Klaus saying that the script worked (I mis-read and thought it was Keram writing this) duh!
Secondly - that you needed an 'else' clause setting the hilite to false (maybe there are different defaults on a PC) - well done for tracking that down

Re: check boxes do not reflect the settings
Posted: Fri Dec 20, 2013 6:08 pm
by keram
Hi Klaus,
Klaus wrote:Hint: You should check, if that file is already PRESENT in the docs folder!
If not, then the script will halt at this point in a standalone!
I checked it. If the data file (myAppsData.txt) is not there and I run the standalone then nothing is shown in the form display = no text lines. Then when I click on Select Categories button then no checkboxes are selected. When I select some of them and click on Save button the data file is created, so all works OK.
Klaus wrote:but since your "prefs" file only contains up to 3 characters you could even make it shorter
Right now just 3 characters but as I develop the stack it will be more, like storing the Selected lines (that's why each line has a checkbox next to it; but this is next step to figure out how to do) and later font settings etc. Would that be OK to store all these settings in just 1 file or is it better to have separate data files for each type of setting groups (e.g. 1 for categories, 1 for selected lines, 1 for fonts, size colour etc.)?
Klaus wrote:## Now a clever way to use a BOOLEan value, which can be TRUE or FALSE
## Heavy stuff, but please take the time to fully understand what I am writing,
## it will surely help you to write efficient code in the future!
I'll definitely will havea close careful look at this and try to understand and apply in future.
Thanks a lot!
keram