The easiest way, if there can be only one match, is by using the
CB_FINDSTRING or CB_FINDSTRINGEXACT messages ...
sItemToFind = "Hello World"
matchIndex = SendMessage(combo1.hwnd, CB_FINDSTRINGEXACT, -1, ByVal
sItemToFind)
if matchIndex >-1 then msgbox "the item is index " & matchIndex
CB_FINDSTRINGEXACT (or LB_* for list boxes) does just that ... if the combo
entry was "Hello World here I come" CB_FINDSTRINGEXACT would fail above.
CB_FINDSTRING on the other hand would locate the item. Note however if the
item was "I'd like to say Hello World", neither messages would find the item
since the item does not begin with the words "Hello World".
--
Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Niels" <ni****@hollandridderkerk.nl> wrote in message
news:b1*************************@posting.google.co m...
: Hello,
: I'm trying to get te index of a specific text in a ComboBox.
: The ComboBox is filled by searching for filenames in a directory.
: The text of the last item selected in the ComboBox is saved in a
: textfile in the OnExit Event of the Mainform.
: While loading the Mainform I want the text that was saved in the file
: to be compared with the items in the ComboBox ad get the index of the
: found item, so that I can set it as selected.
:
: I thought i could do it something like this, but the program hangs
: before I can see anything.
: ---------
: Code
: ---------
: Dim i, As Integer
: Dim line As String
: For i = 0 To ComboBox1.Items.Count
: If ComboBox1.Items(i) = line Then
: IndexFound = i
: Exit For
: End If
: Next
: ---------
: Code
: ---------
:
: Can anyone help me please,
:
: Thanx