Add value of radio buttons to variable

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

ClipArtGuy
Posts: 253
Joined: Wed Aug 19, 2015 4:29 pm

Re: Add value of radio buttons to variable

Post by ClipArtGuy » Tue Oct 23, 2018 4:41 pm

It seems to be working as expected with the above script in the evaluate button, but only IF the radio buttons have been checked. If a group doesn't have a hilitedbutton, then it will throw an error. I think to fix this, you will need to check that there is indeed a hilited button in each group. I'm not sure of the best way to do this, as I rarely use radio buttons myself. If you want, I can upload your stack here for others to look at.

EDIT: I think I've got it:

Code: Select all

global VPname, neuroscore

on mouseup
   put 0 into neuroscore
   repeat with x = 1 to 3
      if the hilitedbuttonname of grp ("radiogrp" & x)  is empty then
         answer "Please complete survey"
         exit mouseup
      end if
      add the label of btn (the hilitedbutton of grp ("radiogrp" & x)) of grp ("radiogrp" & x) to neuroscore
   end repeat   
   put empty into VPname
   put fld "name" of card "GCS" into line 1 of VPname
   put label of button "Sex" of card "GCS" into line 2 of VPname
   if fld "name" is not empty and label of button "Sex" is not "choose sex" then
      go next card 
   else
      answer "Fill in all fields"
      
   end if
end mouseup


Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Add value of radio buttons to variable

Post by Klaus » Tue Oct 23, 2018 5:30 pm

The "nature" of a group of radiobuttons is that ONE button is always hilited, sSo if there is no button hilited the this would be bad UI design. Check one of the buttons of every group and save the stack before you give it to your users.

Or do some checks in your script(s):

Code: Select all

...
repeat with x = 1 to 3

     ## For debugging we should use some extra variables, so we can see and check their content:
     put the hilitedbutton of grp ("radiogrp" & x) into tButton

     ## No button checked, go to next group
     if tButton = 0 then
       next repeat
     end if  

      ## Button checked, so we can get its label and add it to whatever...  
      add the label of btn tButton of grp ("radiogrp" & x) to neuroscore
end repeat
...

Tobi.hhu
Posts: 7
Joined: Mon Oct 22, 2018 6:17 pm

Re: Add value of radio buttons to variable

Post by Tobi.hhu » Tue Oct 23, 2018 7:08 pm

Its working! :D :D ClipArtGuys re-edited the script above. Everything ist working now. Thanks so much to all of you guys!!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”