Reading groups of RadioButtons

Post

Posted
Rating:
#1 (In Topic #229)
Avatar
Administrator
sholzy is in the usergroup ‘unknown’
Is there a more elegant (or proper) way of reading the value(s) of a group of RadioButtons to determine which one is True?

For instance… If I have a group of 4 RadioButtons (in a panel) and I want to set the selected button's value in a config file (or just to determine which button is "True"), is there a better way than doing this…

Code (gambas)

  1.     If RadioButton1.Value = True Then hSetting["System/Header/Main"] = 0
  2.     If RadioButton2.Value = True Then hSetting["System/Header/Main"] = 1
  3.     If RadioButton3.Value = True Then hSetting["System/Header/Main"] = 2
  4.     If RadioButton4.Value = True Then hSetting["System/Header/Main"] = 3
  5.  
Or is that the only way?

sholzy
Gambas One Site Director

To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
jornmo is in the usergroup ‘Regular’
 How about defining the Action property on all RadioButtons, create a subroutine for that action that defines the value of a global variable that get's the value from the RadioButton's Tag property (using .Last). From there you save the setting using that variable.

Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
If you change the name of the RadioButtons to: -
RadioButton0
RadioButton1
RadioButton2
RadioButton3

Add a group name to all the RadioButtons e.g AllRadioButtons then add the following code: -

Code (gambas)

  1. Public Sub AllRadioButtons_Click()
  2.  
  3. Settings["System/Header/Main"] = Right(Last.name)
  4.  

This is a solution provided you only want to catch this when the value of the RadioButtons change.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Administrator
sholzy is in the usergroup ‘unknown’
 Thanks, guys! That jogs my memory a little (it's not so good anymore). IIRC, I used a similar way (using .Last) of doing it way back on Gambas 2.

My 3-year old appointment reminder app has had numerous RadioButtons added to the config section over the years and I'm starting to look at reducing the number of code lines. I may even look at switching to using ComboBoxes like I do in my inventory app. ComboBoxes has the added benefit of reducing GUI clutter.

sholzy
Gambas One Site Director

To report bugs in the Gambas IDE:
Official Gambas Bug Tracker
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
jornmo is in the usergroup ‘Regular’
Ahh, yes! Sorry :) I meant Group, not Action.

Online now: No Back to the top
1 guest and 0 members have just viewed this.