How to obtain a value from combobox

In my spreadsheet I have a combobox named “Combo_1”,
I would like to pass the string from the combobox to StarBasic;
I had found this comand:

oMyCombo = oSheet.DrawPage.Forms.getByName(“MyForm”).getByName(“MyComboBox”)

but I don’t understand this string “.Forms.getByName(“MyForm”).” :confused:

Good Life

LO: 5.3.1 e 5.2.6
SO: Win 7 e 10

Hello Fede, when you add a control such as a Combobox to your sheet, it is placed inside a virtual (invisible) container called a “Form”. By default the name of such a virtual Form in Calc is also “Form”.
To see the hierarchy of Forms and controls in your sheet, open the Toolbar called “Form Design” and press the “Form Navigator” button ( 6th button from the left ).
To get the current value from your ComboBox, you could write something like:

Sub on_event( oEvent )
    Dim oCtrl, oForm, oSheet, sVal as String
    oSheet = oEvent.getSpreadSheet()
    oForm = oSheet.DrawPage.Forms.getByName("Form")  REM your Form name here
    oCtrl = oForm.getByName( "Combo_1" )
    sVal = oCtrl.getCurrentValue()
End Sub

Very good, but to be clear I think, especially for the beginner, you might want: Dim oCtrl as Object, oForm as Object, oSheet, sVal as String. Without these the oCtrl and oForm variables are variant containers (allowing any type) not specifically Object (type) containers.

Thank You Mr @Librebel,
I have a question in Your code:
how I must to interpreter the keyword “oEvent”?

It is the rsult of another function/sub?

Thank you

yw @Fede1 :),
The oEvent parameter ( not a keyword ) is automatically supplied for any event handler callback function.
It often holds the type and Source of the event. It’s called “oEvent” in the example above, but it could be another name.

Thank You, @Librebel.
I had tried to use your code,
But there is an error that I don’t understand.

Sorry, but I don’t understand

this is my situation

(edit: activated screenshots)

Hi Fede, the Error message means: that there is no such element named “Combo_Lang” in your form called “Formulario” …
Please check if the name of the ComboBox is actually spelled as “Combo_Lang”,
and check if this ComboBox is a direct child of the Form “Formulario”.

On the second screenshot, it’s unclear why did you do the Forms("Formulari") instead of simple Forms (like you did on the first one).

@Fede1, In the future, please add your comment, i.e. “Thank you, …” as a comment and not place it here as an answer, as it is not an answer. Thanks.

Hello Fede, following the comment by Mike Kaganski above, try this line instead:

oMyCombo = oSheet.DrawPage.Forms.getByName( "Formulario" ).getByName( "Combo1" )

run :smiley: thanks