selected

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

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

selected

Post by robm80 » Wed Jul 23, 2014 7:31 am

In a substack a group contains 19 check boxes, some of them are checked.
With put selected of button "foo" , the answer is always "false", no matter the button is checked or not.
The same with: put selected of button "foo" of stack "Recepten"
That's why my script fails, the debugger told me:

Part of script:

Code: Select all

repeat with i=1 to tRnumber
go card i of stack "recepten"
	repeat with v=1 to tBtnNumbers
		if selected of button (item v of tBtnList) = true then----------------NOT ACCEPTED
			put name of button (item v of tBtnList) & cr after tNameList
		end if
	end repeat
end repeat
In short: what's wrong with "selected ", or is the fault elsewhere?
Thanks again
Rob

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: selected

Post by jmburnod » Wed Jul 23, 2014 7:48 am

Hi Rob,

"selected" works with a selected control with pointer tools.
In your case you have to use "hilite" property

Code: Select all

 if the hilite of button (item v of tBtnList) = true then----------------should be ACCEPTED
Best regards
Jean-Marc
https://alternatic.ch

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

Re: selected

Post by Klaus » Wed Jul 23, 2014 12:24 pm

Hi Rob,

you obviously still did not look (at least) at the "Controls" stack from the scripting conferences, but you really should!


Best

Klaus

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: selected

Post by robm80 » Wed Jul 23, 2014 5:38 pm

Hi J-M
if the hilite of button (item v of tBtnList) = true then----------------should be ACCEPTED
Thanks, downloaded "control" by Klaus just a few minutes ago. If I had read it before, I had avoided this question.

Hi Klaus
you obviously still did not look (at least) at the "Controls" stack from the scripting conferences, but you really should!
See above.
Thanks

Rob

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: selected

Post by robm80 » Wed Jul 23, 2014 9:53 pm

Why my script stops?

The goal is to find a card amidst 112 cards in the substack "recepten", where the buttons are highlited like in this field "spec":
sshot-07.jpg
Here a picture of card 1 of the substack:
sshot-06b.jpg
On the right side of this card you see 19 buttons; 4 of them are checked. Each card may show different checked boxes.

I use this script that stops at the line indicated in the script below and sends an errormessage: button "spec": execution error at line 14 (Chunk: no such object) near "fruit", char 17
But there is a button "fruit" as the property inspector confirms. The most top button on the picture.
I hope someone can clear this mistery, that puzzled me the whole day.

Code: Select all

on mouseUp
   set lockscreen to true
   put "fruit,hartig,indisch,kip,overig,vegetarisch,vis,vlees,zoet,bijgerechten,hapjes,hoofdgerechten.,pasta,salades,soepen,taarten,toetjes,voorgerechten,ovenchotel" into tBtnList  ----(names of all 19 buttons)
   put number of items of tBtnList into tBtnNumbers
   put the selectedText of fld "spec" into tOrgList
   put number of cards of stack "recepten" into tRnumber
   
 repeat with i=1 to tRnumber
   go card i of stack "recepten"
   repeat with b=1 to tBtnNumbers
      if hilite of button (item b of tBtnList) = true then   ---------------here the execution stops
         put name of button (item b of tBtnList) & cr after tNameList
      end if
     end repeat
      
    sort lines of tNamelist
      if tNamelist = tOrglist then
         put fld "titel" &cr after tTempfield  ------------fld titel is the top field on the picture
      end if
   end repeat
end mouseUp
Thank you, Rob

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

Re: selected

Post by Klaus » Wed Jul 23, 2014 11:54 pm

Hi Rob,

not sure what goes wrong, but try this script, note my comments at the beginning of the repeat loop:

Code: Select all

on mouseup
  lock screen
  put "fruit,hartig,indisch,kip,overig,vegetarisch,vis,vlees,zoet,bijgerechten,hapjes,hoofdgerechten.," & \
      "pasta,salades,soepen,taarten,toetjes,voorgerechten,ovenchotel" into tBtnList
  put number of items of tBtnList into tBtnNumbers
  put the selectedText of fld "spec" into tOrgList
  put number of cards of stack "recepten" into tRnumber
  repeat with i = 1 to tRnumber
    ## go card i of stack "recepten"
    ## No need to actually GO there, we can address every single object directly from the "distance", see below:
    repeat with b = 1 to tBtnNumbers
      put item b of tBtnList into tBtnName
      if the hilite of button tBtnName of cd i of stack "recepten" = true then
        ## put the name of button (item b of tBtnList) of cd i of stack "recepten" & cr after tNameList
        ## the name of btn xyz -> button "xyz"
        ## I'm sure you only need the SHORT name, so I use the item of the button list :-)
        put tButtonName & cr after tNameList
      end if
    end repeat
    sort lines of tNamelist
    if tNamelist = tOrglist then
      put fld "titel" &cr after tTempfield
    end if
  end repeat
  unlock screen
end mouseUp
Best

Klaus

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: selected

Post by robm80 » Thu Jul 24, 2014 7:45 am

Thanks Klaus,
I had to change something:

Code: Select all

put tButtonName & cr after tNameList
to

Code: Select all

put button tBtnName into tButtonName
 put tButtonName & cr after tNameList
But now the execution stops again at line 17: put button tBtnName into tButtonName
errormessage: button "spec": execution error at line 17 (Chunk: no such object) near "fruit", char 10
button "fruit" is present and highlited. In previous scripts I had the same errormessage.

This is thew way I builded the substack: first I made the textfields and gave them a background behaviour, then I made the buttongroup
and copied it from page to page, so on each page different buttons could be checked.

Hope you can make a correction again,
Rob

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

Re: selected

Post by Klaus » Thu Jul 24, 2014 11:51 am

Oh, sorry, a typo, my fault:

Code: Select all

...
if the hilite of button tBtnName of cd i of stack "recepten" = true then
        ## put the name of button (item b of tBtnList) of cd i of stack "recepten" & cr after tNameList
        ## the name of btn xyz -> button "xyz"
        ## I'm sure you only need the SHORT name, so I use the item of the button list :-)
        ## put tButtonName & cr after tNameList
        put tBtnName & cr after tNameList
      end if
...

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: selected

Post by robm80 » Thu Jul 24, 2014 1:17 pm

I send you the script again, pleas read the commments in it

Code: Select all

on mouseup
   lock screen
   put empty into tNamelist------------------------------------------------the namelist sometimes is crowded with the same lines
   put "fruit,hartig,indisch,kip,overig,vegetarisch,vis,vlees,zoet,bijgerechten,hapjes,hoofdgerechten.," & \
         "pasta,salades,soepen,taarten,toetjes,voorgerechten,ovenchotel" into tBtnList
   put number of items of tBtnList into tBtnNumbers
   put the selectedText of fld "spec" into tOrgList
   put number of cards of stack "recepten" into tRnumber
   repeat with i = 1 to tRnumber
      repeat with b = 1 to tBtnNumbers
         put item b of tBtnList into tBtnName
         if the hilite of button tBtnName of cd i of stack "recepten" = true then --------------------here the execution stops at random, why??
                                                                                                                                    -----error message: button "spec": execution error at line 17 (Chunk: no such object) near "fruit", char 10
                                                                                                                                   -  ----or button "Button": execution error at line 11 (Chunk: no such object) near "hartig", char 24
            put tBtnName & cr after tNameList
         end if
      end repeat
      --    sort lines of tNamelist--------------------------------the namelist is so far in alphabetic order, but with ''sort lines'' it becomes a disorder.
      if tNamelist = tOrglist then ------------------------------even when the two are exactly the same, according to the debugger, nothing happens !
         put fld "titel" &cr after tTempfield
      end if
   end repeat
   
   if tTempfield=null then
      answer "niets gevonden"
   else
      sort tTempfield
      show group "index"
      hide group "criteria"
      put "gerechten met de gewenste criteria" into fld "titel"
   end if
   unlock screen
end mouseUp
Hope you have the time to correct it
Rob

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

Re: selected

Post by Klaus » Thu Jul 24, 2014 2:10 pm

The script looks OK, I may need to take a look at your stack!
Can you post it here, or a stripped down version?
Hint: You need to ZIP the stack to post here.

But first try this in a button:

Code: Select all

on mouseup
  answer (there is a btn "fruit" of cd 1 of stack "recepten")
end mouseup
and tell me what the dialog shows!


Best

Klaus

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: selected

Post by robm80 » Thu Jul 24, 2014 4:20 pm

Here is the zip:
Quisinerie.zip
(71.31 KiB) Downloaded 243 times
Please concentrate on the 2 red buttons on top. After your correction
I shall place them where they belong.

All calls for pictures are excluded.

Succes and thanks, Rob

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

Re: selected

Post by Klaus » Thu Jul 24, 2014 5:17 pm

Hi Rob,

1. -> if tTempfield= null then...
Please check NULL in the dictionary, you need to check for EMPTY here:
-> if tTempfield= EMPTY then...

2. On your card number 112, there IS in fact NO button named "hartig"!
That button is named 2 (using number as object names is a BAD idea!) and has only the LABEL "hartig".

I hope nr. 2 embarrasses you A LOT! 8)


Best

Klaus

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: selected

Post by robm80 » Fri Jul 25, 2014 9:14 am

I changed the script totally,because of a big fault.
I changed null for empty and repaired the button in the substack.
But now there is another problem.

Code: Select all

on mouseup
   put the selectedText of fld "spec" into  tOrgList
put number of lines of tOrglist into tBtnnumbers
put number of cards of stack "recepten" into tRnumber
repeat with i = 1 to tRnumber
   repeat with b = 1 to tBtnNumbers
      put line b of tOrgList into tBtnName
      if the hilite of button tBtnName of cd i of stack "recepten" = true then
         put tBtnName & cr after tNameList---------------------------------------------look below
      end if
   end repeat
   delete char -1 of tNameList
   if tNameList=tOrgList then
      put fld "titel" of card i of stack "recepten" & cr after tTempfield
      put empty into tNamelist
   end if
end repeat
end mouseUp
What I get is something like this "hartighartighartighartig" stead
hartig
hartig
etc.
Why that line does not obey to "CR"
Thanks for your comment, Rob

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

Re: selected

Post by Klaus » Fri Jul 25, 2014 12:14 pm

Could you please post the new stack?

robm80
Posts: 161
Joined: Sat May 03, 2014 7:15 am

Re: selected

Post by robm80 » Fri Jul 25, 2014 2:11 pm

Amazing: I cannot reproduce the fault I reported yesterday, but today clouds and rain; that's why!
But I send you the stack with the new script for the left red button.

when I mark as choises (criteria) Fruit,vlees,taarten,oven, problemlessly the good titels are placed in the index.
But for all other combinations of criteris I get "niet gevonden" (not found).
Be sure I started with a real existing combination, found somewhere in the substack.

I cannot find where it goes wrong. I hope you do!
Rob
Quisinerie2.zip
(71.16 KiB) Downloaded 208 times

Post Reply