check boxes do not reflect the settings

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

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

check boxes do not reflect the settings

Post by keram » Fri Dec 20, 2013 12:26 pm

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
Attachments
Data grid Form_save and retrieve settings.zip
(29.07 KiB) Downloaded 246 times
Last edited by keram on Fri Dec 20, 2013 4:24 pm, edited 1 time in total.
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: check boxes do not reflect the settings

Post by dave.kilroy » Fri Dec 20, 2013 12:41 pm

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
"...this is not the code you are looking for..."

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: check boxes do not reflect the settings

Post by keram » Fri Dec 20, 2013 4:23 pm

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
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: check boxes do not reflect the settings

Post by dave.kilroy » Fri Dec 20, 2013 4:29 pm

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...
"...this is not the code you are looking for..."

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: check boxes do not reflect the settings

Post by Klaus » Fri Dec 20, 2013 4:41 pm

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 :D
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! :D


Best

Klaus

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: check boxes do not reflect the settings

Post by dave.kilroy » Fri Dec 20, 2013 4:45 pm

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?
"...this is not the code you are looking for..."

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: check boxes do not reflect the settings

Post by keram » Fri Dec 20, 2013 4:50 pm

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
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: check boxes do not reflect the settings

Post by keram » Fri Dec 20, 2013 5:03 pm

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
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: check boxes do not reflect the settings

Post by Klaus » Fri Dec 20, 2013 5:04 pm

Just tested your stack and it does what it is supposed to!? 8)

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: check boxes do not reflect the settings

Post by dave.kilroy » Fri Dec 20, 2013 5:09 pm

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!
"...this is not the code you are looking for..."

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: check boxes do not reflect the settings

Post by dave.kilroy » Fri Dec 20, 2013 5:12 pm

Ah just read that Klaus's script worked! ...well done Klaus - now to figure out what made the difference...
"...this is not the code you are looking for..."

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: check boxes do not reflect the settings

Post by keram » Fri Dec 20, 2013 5:19 pm

Klaus wrote:Just tested your stack and it does what it is supposed to!? 8)
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 :D

Thanks Dave and Klaus anyway for your attention and help.

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: check boxes do not reflect the settings

Post by Klaus » Fri Dec 20, 2013 5:35 pm

Hi keram,

great! :D

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

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: check boxes do not reflect the settings

Post by dave.kilroy » Fri Dec 20, 2013 5:36 pm

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 :)
"...this is not the code you are looking for..."

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: check boxes do not reflect the settings

Post by keram » Fri Dec 20, 2013 6:08 pm

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
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Post Reply