Ask Your Question
1

How to obtain a value from combobox

asked 2017-04-26 12:21:35 +0200

Fede gravatar image

updated 2017-05-06 09:06:44 +0200

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 flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2017-04-27 10:49:23 +0200

Fede gravatar image

updated 2017-05-05 11:38:54 +0200

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

edit flag offensive delete link more

Comments

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

librebel gravatar imagelibrebel ( 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).

Mike Kaganski gravatar imageMike Kaganski ( 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.

EasyTrieve gravatar imageEasyTrieve ( 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" )
librebel gravatar imagelibrebel ( 2017-05-05 17:26:26 +0200 )edit

run :D thanks

Fede gravatar imageFede ( 2017-05-06 08:53:34 +0200 )edit
2

answered 2017-04-26 23:38:25 +0200

librebel gravatar image

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
edit flag offensive delete link more

Comments

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.

EasyTrieve gravatar imageEasyTrieve ( 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

Fede gravatar imageFede ( 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.

librebel gravatar imagelibrebel ( 2017-05-08 13:22:12 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-04-26 12:21:35 +0200

Seen: 399 times

Last updated: May 06 '17