Start a new topic

v38 Radio Buttons - How to do a workaround

So, new with Version 0.38 - the radio button has finally be introduced


and it DOES NOT WORK ... ARRRGGG!.


The Radio Buttons behaves exactly like a round checkbox: So here it is


A work around to get your Radio Buttons to function properly.



Two Radio Groups of Three Radio Buttons each.

Material List
  • Numeric Variable on page to hold first radio group called rg1
  • Numeric Variable on page to hold second radio group called rg2
  • Text Component t0 for Page Title
  • Text Component t7 for Group Title
  • Radio buttons r0,r1,r2 for group 1
  • Text Components t1,t2,t3 for group 1
  • Text Component t8 for Group 2 Title
  • Radio buttons r3,r4,r5 for group 2
  • Text Components t4,t5,t6 for group 2
  • Hotspot m0 to hold some code

1) Set Text Component values for Titles and Labels
  • Group titles .ycen top and select a backround color in .bco
  • Set text components in the group with same background in .bco
  • Don't forget with Group Titles "send-to-back" (down arrow on toolbar)

2) Start all radio buttons to off with .val of 0

3) Set Variables rg1 and rg2 to .val of 0

4) With each text label for the Radio Buttons, set the Text Components Touch Press Event to click r0,1 where r0 matches the radio button for this label

5) With each Radio button, set the Touch Press Event with these two lines:

rg1.val=0  // where rg1 is group 1, and 0 is the button number 0 for r0, 1 for r1
click m0,1 // this is the Hotspot Touch Press Event.

6) Set the Hotspot location out of the way, .h of 5 and .w of 5

7) In the hotspot Touch Press Event place the following code

if(rg1.val==0) // Check groups value holder to see if this is current selection
{
r0.val=1         // if it is current selection, set radio button to on
}else
{
r0.val=0         // if it is not current selection, ensure radio button is cleared
}
if(rg1.val==1)
{
r1.val=1
}else
{
r1.val=0
}
if(rg1.val==2)
{
r2.val=1
}else
{
r2.val=0
}
if(rg2.val==3)
{
r3.val=1
}else
{
r3.val=0
}
if(rg2.val==4)
{
r4.val=1
}else
{
r4.val=0
}
if(rg2.val==5)
{
r5.val=1
}else
{
r5.val=0
}

8) Finally in your page Postinitialize Event, set the defaults and call click to update

rg1.val=0
rg2.val=4
click m0,1

9) To retrieve the choices over serial when selections have been made use:

get rg1.val
get rg2.val

And there you have it.  Two functional radio groups of three buttons each.
Find attached the version 0.38 HMI file for you to see how it was done.

Regards
hmi
(18.7 KB)

3 people like this idea
1 Comment

Thanks


1 person likes this
Login or Signup to post a comment