Ask Your Question

Need the text from a single ListBox selection assigned to a string variable

asked 2016-03-26 17:31:04 +0100

docbda gravatar image

updated 2016-03-26 17:37:35 +0100

I'm attempting to assign the text from a Base form ListBox single selection to a string variable. Using the following code gives me a 'Property or Method not found' error.

Sub GetLBtext

Dim oForm As Object
Dim oField As Object
Dim var As String

oForm= ThisComponent.Drawpage.Forms.getByName("Form Name With ListBox_1")
oField = oForm.getByName("ListBox_1").getSelectedItem()
var = oField

End Sub

Upon some research, I came accross this discussion at the Open Office Forum that I'm pretty sure contains the answer I'm looking for, but its content is way over my head. Any chance I could get someone out there to explain to me how to properly go about this? As you may have guessed I'm a total LO Basic noob, so please be gentle :)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2016-03-26 18:07:40 +0100

Ratslinger gravatar image

You're close. Try:

oField = oForm.getByName("ListBox_1")
var = oField.SelectedValue
edit flag offensive delete link more


Right as usual! Thanks, Ratslinger

docbda gravatar imagedocbda ( 2016-03-26 18:32:45 +0100 )edit

FYI - try better naming conventions. 'var' is not good. You will have no idea what that is six months from now. 'oField' is an object ( thus the 'o'). 'sLB1Selection' is a string (thus the 's'). When you use that later in the code you have a better idea what it is. Be descriptive. Imagine variables names String1, String2, String3, etc. No idea what they are.

Ratslinger gravatar imageRatslinger ( 2016-03-26 18:37:06 +0100 )edit

True enough, and thanks for the tip. I just used variable names that described what they represented in the code snippet I posted. My real code has better names and is properly commented. Nice to know you've got my back...

docbda gravatar imagedocbda ( 2016-03-26 18:58:03 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-03-26 17:31:04 +0100

Seen: 372 times

Last updated: Mar 26 '16