0

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:

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:

    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

   put gSelectedCategories into URL ("file:./myAppsData.txt")

   go back
end mouseUp

Here is the link to the stack:

https://dl.dropboxusercontent.com/u/99863601/Data%20grid%20Form_save%20and%20retrieve%20settings.zip

or here:
http://filecloud.io/lk06h3py

or here:
http://www.divshare.com/download/24928436-897

the

How to correct this problem?

Thanks in advance.

keram

=======================

I fixed it now by changing the code on the stack level:

        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

keram

mark
  • 222
  • 1
  • 9

3 Answers3

1

When you save the data, it is tab-delimited. When you read back the data, the script assumes the default delimiter which is a comma. If you set the itemDelimiter to tab before reading the values, it should work.

It isn't clear whether the user is allowed to select multiple items or only one. If it is only one, then you don't need to test for items at all, there will only be a single character in the data ("s","m" or "l".)

Jacque
  • 416
  • 2
  • 7
  • Thanks Jacque. I added the second itemDelimiter now in the stack script. Is it necessary to do it when it was set already once (see above)? But anyway, when I reopen the stack all the 3 check boxes are selected even when I saved only one or two to the text data file. Yes, the user should be able to select 1,2 or 3 categories. (I uploaded the modified version of the stack - still not working properly). – mark Dec 20 '13 at 08:12
1

I've just tested your stack and it works for me here (OSX9), are you doing this on a mac or pc? I'm wondering if the problem might be the route to the text file and whether it would be worth adding

   set the defaultFolder to specialFolderPath("Documents")

to the script of your 'save' button.

But actually it sounds like you just need to do some debugging and research answers to questions such as: is the text file being created where you expect it to? Does it contain what you think it should? Your checkboxes seem to be highlighted by default, what happens if you unhighlight them and try your routine, do you still get them all showing as highlighted? etc etc etc

Dave Kilroy

Dave Kilroy
  • 156
  • 3
  • Thanks Dave! I'm doing it on PC and the text file has been created in the expected Documents folder and the settings have been stored there properly. Now when I added the line that you suggested the checkboxes are not highlighted by default and they retain the saved setting properly. Finally it works OK! – mark Dec 20 '13 at 10:05
  • Actually I made the above comment too hastily. After playing with it few more times it shows not to be correct. The 3 checkboxes are now always highlighted on reopening the stack even when they have not been selected, also when no checkboxes have been selected at all. So the problem remains. – mark Dec 20 '13 at 10:42
  • 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! – Dave Kilroy Dec 20 '13 at 11:38
  • Actually Keram, I only noticed code to save to a text file in the script 'save' button - I don't remember seeing a 'onCloseStack' or similar handler, so the state of your checkboxes won't be saved on exit as you mention above but only when you click the 'save' button – Dave Kilroy Dec 20 '13 at 14:48
  • Yes, you are right. I had it in both places but removed from the onCloseStack handler since it's not necessary - it's enough in the Save button. Re your previous suggestion for debugging: 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. I'll keep on experimenting, trying to find the bugs. – mark Dec 20 '13 at 15:21
0

Cannot access your stack. So I cannot know what the variables "s", "m" and "j" are, or if they properly fit into "the items" of the data pulled from that file.

You do know that items are chunks of text delimited by commas, correct? It sounds like the formatting is not right, because the command to set the hilites of those buttons seems straightforward. So what does "s" contain, and more importantly, how is the returned text formed?

Craig Newman

dunbarx
  • 146
  • 2
  • Sorry that the dropbox link does not work for you. I added 2 more links to download the stack - see above. – mark Dec 20 '13 at 04:17
  • Added the code showing how the "s", "m" and "l" are put to the variable. – mark Dec 20 '13 at 04:45