PDA

Click to See Complete Forum and Search --> : What am I doing wrong here?


tonyevans
Oct 17th, 2001, 05:30 PM
<code>
Const LB_GETCURSEL = &H188
Const LB_GETSELITEMS = &H191
Const LB_SETITEMDATA = &H19A
Const LB_ADDSTRING = &H180
Const LB_GETTEXT = &H189
Const LBN_DBLCLK = 2

Private Function GetDataFromListbox() As String
Dim Index As Long
Dim lstSize As Long
Dim lstText As String

Index = SendMessage(lngHwndlstData, LB_GETCURSEL, 0&, ByVal 0&)
lstSize = SendMessage(lngHwndlstData, LB_GETTEXTLEN, Index, ByVal 0&)
lstText = Space(lstSize)
Call SendMessage(lngHwndlstData, LB_GETTEXT, Index, ByVal lstText)

GetDataFromListbox = lstText
End Function
</code>

And lngHwndlstData is the handle to my listbox. I'm just trying to get the data from the listbox.

jim mcnamara
Oct 18th, 2001, 05:28 AM
You need to check for LB_ERR returns



Const LB_ERR = (-1)


When you get values back from these callls. The LB could be empty for instance.

Here's an example of calling SendMessage to get text from a listbox (the example is not checking for LB_ERR, either)

http://www.vbapi.com/ref/l/lb_gettext.html