|
-
Sep 13th, 2002, 06:25 AM
#1
Thread Starter
Addicted Member
User32 problem
Hi,
Iam trying the following code for searching a ListBox Control.
VB Code:
Const LB_FINDSTRING = &H18F
Private Declare Function SendMessage Lib "User32" _
Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As _
Integer, ByVal wParam As Integer, lParam As Any) As Long
iListIndex = SendMessage(m_listOfChangedDO.hWnd, LB_FINDSTRING, -1, ByVal strName(i))
If I do a sample application, Iam getting the result correctly, but if I include this code in my application it crashes saying an error:
VB6 caused a general protection fault
in module USER.EXE at 000c:00003ebb
Is there something wrong here? Or is there any better way to search a string in a ListBox?
Thanks,
Pres/.
-
Sep 13th, 2002, 07:20 AM
#2
I don't understand this line of code
VB Code:
iListIndex = SendMessage(m_listOfChangedDO.hWnd, LB_FINDSTRING, -1, ByVal strName(i))
It would appear that you have dimmed iListIndex as an integer somewhere, and I'm not sure why you are not getting an immediate error. Where are you executing this code? Typically, I have a textbox about my listbox in which the user types stuff in, and the search line executes in the change event of the textbox. If m_listOfCHangedDO is the name of your listbox, try this
VB Code:
Private Sub txtSearch_Change()
m_listOfChangedDO.ListIndex = SendMessage(m_listOfChangedDO.hWnd, LB_FINDSTRING, -1, ByVal CStr(txtSearch.Text))
End Sub
-
Sep 13th, 2002, 09:09 AM
#3
Thread Starter
Addicted Member
Getting the ListIndex
Hi,
Instead of passing a Textbox value, Iam just passing a string and trying to see whether the string is there in the ListBox.
m_listOfChangedDO is my list box. And strName(i) is a string which I want to locate in the ListBox. iListIndex is an integer which gets the Index of the String, if found in the ListBox.
Will it only work with a value from a text box? or will it work with a string?
Thanks,
Pres
-
Sep 13th, 2002, 09:19 AM
#4
I just tried it using a string. I got no errors, but it didn't find the string I was looking for.
This is the first time I've ever tried using this routine with anything other than the ListIndex of the Listbox, and based on what happened (or more accurately, what didn't happen), I'm going to say that no, it doesn't appear that you can use a string to locate an item in your listbox.
One thing I tried, that did work, was to pass the string, as a whole, to the textbox, and that worked. It found the listbox item instantly, but, as I said, it did not find the listbox item when the string was passed directly to the API.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|