Ask Your Question
0

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

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

docbda gravatar image

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

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 https://forum.openoffice.org/en/forum... 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 reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Ratslinger
close date 2016-03-26 18:46:15.493267

1 Answer

Sort by » oldest newest most voted
1

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

Ratslinger gravatar image

You're close. Try:

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

Comments

Right as usual! Thanks, Ratslinger

docbda gravatar imagedocbda ( 2016-03-26 18:32:45 +0200 )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 +0200 )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 +0200 )edit

Question Tools

1 follower

Stats

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

Seen: 176 times

Last updated: Mar 26 '16