# How to obtain a value from combobox

Hello! 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")." :/

Good Life

LO: 5.3.1 e 5.2.6 SO: Win 7 e 10

edit retag close merge delete

Sort by » oldest newest most voted

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

C:\fakepath\Error.PNG

Sorry, but I don't understand

this is my situation

C:\fakepath\Formulario.png

more

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

( 2017-04-27 17:03:21 +0200 )edit

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

( 2017-05-05 13:18:56 +0200 )edit

@Fede, 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.

( 2017-05-05 17:08:10 +0200 )edit

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

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

( 2017-05-05 17:26:26 +0200 )edit

run :D thanks

( 2017-05-06 08:53:34 +0200 )edit

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
oForm = oSheet.DrawPage.Forms.getByName("Form")  REM your Form name here
oCtrl = oForm.getByName( "Combo_1" )
sVal = oCtrl.getCurrentValue()
End Sub

more

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.

( 2017-05-05 17:04:41 +0200 )edit

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

( 2017-05-08 08:44:23 +0200 )edit

yw @Fede :), 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.

( 2017-05-08 13:22:12 +0200 )edit