Ask Your Question
1

retrieving the value from a multi radio button option group

asked 2015-06-26 18:33:10 +0200

jay Arr gravatar image

updated 2015-08-25 06:58:56 +0200

Alex Kemp gravatar image

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:

image description

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
0

answered 2015-06-29 01:20:45 +0200

doug gravatar image

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)

edit flag offensive delete link more
1

answered 2015-06-29 10:08:06 +0200

pierre-yves samyn gravatar image

updated 2015-06-30 16:31:46 +0200

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

edit flag offensive delete link more

Comments

Thank you.

jay Arr gravatar imagejay Arr ( 2015-06-29 11:34:24 +0200 )edit

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

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

thank you :)

pierre-yves samyn gravatar imagepierre-yves samyn ( 2015-06-30 16:43:16 +0200 )edit
1

answered 2015-06-30 16:02:58 +0200

jay Arr gravatar image

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.

edit flag offensive delete link more

Comments

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

pierre-yves samyn gravatar imagepierre-yves samyn ( 2015-06-30 16:33:36 +0200 )edit

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

doug gravatar imagedoug ( 2015-06-30 16:37:36 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-06-26 18:33:10 +0200

Seen: 1,770 times

Last updated: Jun 30 '15