Switch & Case button group

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

Post Reply
dbailey
Posts: 23
Joined: Fri Sep 06, 2013 4:47 pm

Switch & Case button group

Post by dbailey » Wed Sep 25, 2013 10:51 am

Hi All,


If I have a group of buttons on a card how do I check which button has been pressed/selected. I understand using the switch & case commands but not sure how to check against the buttons.

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

Re: Switch & Case button group

Post by jmburnod » Wed Sep 25, 2013 11:33 am

Hi,

For radio btn
You can use the radiobehavior (hilite one radio button at time" of the group

or write your own script to check the changed state of each btn
Something like that:

Code: Select all

on mouseUp
   put getNumHilitedBtnInGroup(MyGroupName)
end mouseUp

function getNumHilitedBtnInGroup pGroup -- return a list of the number of each hilited btn like "1,3,5"
   put the num of btns of group pGroup into nb
   put empty into tBtnHilited
   repeat with i = 1 to nb
      if the hilite of btn i of group pGroup then
         put i & "," after tBtnHilited
      end if
   end repeat
   delete char -1 of tBtnHilited
   return tBtnHilited
end getNumHilitedBtnInGroup
Best
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Switch & Case button group

Post by dunbarx » Wed Sep 25, 2013 2:50 pm

Hi.

You can also just check the "target" in a mouseUp handler. Not sure where in your project that handler ought to be placed, or whether each button might have its own. And I am not sure how the buttons in your group are named or distinguished, but:

Code: Select all

on mouseup
answer the target
end mouseUp
Craig Newman

Post Reply