Retrieving the value from a multi radio button option group

LO Version: 4.4.3.2 on OSX 10.10.3

I need to be able to retrieve the value from a radio button option group which is on a BASE form with a macro.

I have my option group setup like this

Name: Contents

Option1: Title

Option2: Title, Version & Date

Option3: Details

I’ve set this up with the Group Box Wizard: so that the form navigator

knows this as “Group Box 1” and has all three buttons with the name “RadioGroup1”

and option1 has a reference value (on) of 1 and off of Zero

and option2 has a reference value (on) of 2 and off of Zero

and option3 has a reference value (on) of 3 and off of Zero

The option group looks like this:

Option Group

[I know that “Group Box 1” is a form control and I can dump the properties]

So how do I retrieve the particular reference value (which is NOT assigned to a data field) with a macro once the user has chosen and clicked on the radio button.

FYI: I have three of these radio option button groups on the form and plan to retrieve all three values once the user has clicked on a “confirm selection” button. This is the form which I plan to use:

Hi

Another approach by the group:

Sub PysAfficher

dim oDoc as object, oForm as object, oCurrent as object
dim oValues()

oDoc = thiscomponent										
oForm = oDoc.drawpage.getforms().getbyname("MainForm")		
oForm.getGroupByName("RadioGroup1", oValues())				

for each oCurrent in oValues()								
	if oCurrent.state = 1 then								
		msgbox oCurrent.label & " : " & oCurrent.RefValue
		exit for
	end if
next 

End Sub

[EDIT]

The given code was taken from an old database. In this old format, macros were stored in the forms (i.e. a Writer document ) and not in the database. I should have thought, I’m very sorry. I attach an updated example:

EtiquettesSelonRadio.odb

Regards

Thank you.

good use of getGroupByName and For . . . Each

thank you :slight_smile:

Thank you Doug & Pierre-yves.

However Pierre-yves your solution works for a WRITER-form and not for a BASE-form. Apologies if I didn’t make that clear.

And Doug your solution works IF the option group section is to be AND/ORed i.e. allowing the user to select option 1 AND/OR option 2 AND/OR option 3. That’s why you have the get bynames in the code all different. However when I use the option group wizard it names my three groups like this:

image description

See each ‘Group Box n’ has a named buttons ‘RadioGroupn’ because I want the user to choose only 1 option from each of the 3 option groups.

I have figured out the code get the user selections:

dim i			as integer
dim selected(3)	as integer

    for i=1 to 3
    set optionGroup= frm_ReportingOptions.OptionGroup("RadioGroup"+cstr(i))
    	selected(i)=optionGroup.value+1
        msgbox "option Group Box" & cstr(i) & "=" & cstr(selected(i))
    next i

note the line …OptionGroup.value+1

that’s because it returns the position of the option in each group selected starting at zero.

I hope this discussion might help others.

It was for a database form, not exactly a writer form. See my edited answeer where I can attach an example. Sorry…

Thank you for sharing these approaches, had not previously studied the option button group,

Here is the answer using a macro that runs on a button on the same form, and it returns the the value for the active radio button in a message box. The below checks the state of each button and returns the reference of the activated button. For demonstration, it completes using the SecondaryRefValue but for just one button on assumption that if none are active all are inactive with the same secondary reference value, as you say in your question.

Sub radio (eventObj As Object)
  REM Dim srcObj, buttonObj, parFrm As Object
  Dim valStr As String
  
  srcObj = eventObj.Source
  buttonObj = srcObj.model
  parFrm = buttonObj.parent

  radCtrl3 = parFrm.getByName("Option3")
  radCtrl2 = parFrm.getByName("Option2")
  radCtrl1 = parFrm.getByName("Option1")

  REM MsgBox radCtrl3.dbg_methods
  If radCtrl1.State = 1 Then 
    valStr = radCtrl1.RefValue
  ElseIf radCtrl2.State = 1 Then 
    valStr = radCtrl2.RefValue
  ElseIf radCtrl3.State = 1 Then 
    valStr = radCtrl3.RefValue
  ElseIf radCtrl1.State = 0 Then 
    valStr = radCtrl1.SecondaryRefValue
  End If

  MsgBox valStr

End Sub

(if this answers your question please accept the answer by clicking the check (image description) to the left)