Results 1 to 4 of 4

Thread: User32 problem

  1. #1

    Thread Starter
    Addicted Member MrPresident2k's Avatar
    Join Date
    May 2002
    Location
    INDIA
    Posts
    167

    User32 problem

    Hi,

    Iam trying the following code for searching a ListBox Control.
    VB Code:
    1. Const LB_FINDSTRING = &H18F
    2. Private Declare Function SendMessage Lib "User32" _
    3. Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As _
    4. Integer, ByVal wParam As Integer, lParam As Any) As Long
    5.  
    6. 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/.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    I don't understand this line of code
    VB Code:
    1. 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:
    1. Private Sub txtSearch_Change()
    2. m_listOfChangedDO.ListIndex = SendMessage(m_listOfChangedDO.hWnd, LB_FINDSTRING, -1, ByVal CStr(txtSearch.Text))
    3. End Sub

  3. #3

    Thread Starter
    Addicted Member MrPresident2k's Avatar
    Join Date
    May 2002
    Location
    INDIA
    Posts
    167

    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

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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
  •  



Click Here to Expand Forum to Full Width