# 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:

[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:

edit retag close merge delete

Sort by » oldest newest most voted

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

End If

MsgBox valStr

End Sub


more

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:

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
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.

more

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

( 2015-06-30 16:33:36 +0200 )edit

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

( 2015-06-30 16:37:36 +0200 )edit

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")

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:

Regards

more

Thank you.

( 2015-06-29 11:34:24 +0200 )edit

good use of getGroupByName and For . . . Each ...

( 2015-06-29 14:20:55 +0200 )edit

thank you :)

( 2015-06-30 16:43:16 +0200 )edit