Results 1 to 8 of 8

Thread: text box question

  1. #1

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    I have a text box that is used to select items from a listbox. I have the code so that as you type letters into the text box it automatically moves the selection around in the list box to find the item that matches what you have typed in so far. However, I also want it to fill in the text box with the remainder of whatever is highlighed in the listbox. I want it to perform the same way as Netscape Communicator does when you begin to type in a URL that you have already been to. I've got the code so that it will fill it in the first time it finds a match in the listbox, but if you type another letter, the whole thing disappears and nothing fills it's place. Any suggestions as to why? Here is my code:
    Code:
    General Declarations:
        Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
        Private Const LB_FINDSTRING = &H18F
    
    
    Private Sub txtViewTable_Change()
        Dim x As String
        x = Len(txtViewTable.Text)
        listTables.ListIndex = SendMessage(listTables.hWnd, LB_FINDSTRING, -1, ByVal txtViewTable.Text)
        txtViewTable.SelStart = x
        txtViewTable.SelLength = Len(txtViewTable.Text) - x
    End Sub
    Hope you can shed some light on the subject.

    ------------------
    Ryan
    cornelsen@hotmail.com
    ICQ# 47799046



    [This message has been edited by Gimpster (edited 12-28-1999).]

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Dim X As STRING ?
    Try Long...

    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: RZvika@netvision.net.il
    ICQ: 19552879
    AIM: RYoni69

  3. #3

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    No, that didn't fix the problem. It still only fills in the rest of the text the first time it finds a match.

    ------------------
    Ryan
    cornelsen@hotmail.com
    ICQ# 47799046


  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Actually, X could be string also, even though the return value should be Long. VB is smart enough....it'll convert the return value to string.

    ------------------

    Serge

    Software Developer
    Serge_Dymkov@vertexinc.com
    Access8484@aol.com
    ICQ#: 51055819



  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,175

    Post

    I believe that if you add txtViewTable.Text = listTables.Text to the listTables_Click() event, that it will fix your problem.

    ------------------
    Marty

  6. #6

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    I already have that code in listTable_Click()Event, Marty. Any other ideas? Because it's really stupid the way it's acting right now. Because does exactly what you would expect it to do but only the first time that VB finds a match in the listbox (which is typically just the first letter you type in).


    Also, Yonatan, I have a question for you. I was wondering if you could tell me why I get an "Run-time Error: 380". It happens when you begin typing in a word into the textbox and VB finds a match for it in the listbox, but if you type a letter that does not match any of the entries in the listbox then you get the error. So, just for an example, say you have only two entries that start with the letter "c": crystal and crying. So you type "cry" into the textbox and everything is fine so far, but if you type in a letter that is not a "s" or "i" then you get the error. Hope you can help. Thanks for all of your help so far, everyone.

    ------------------
    Ryan
    cornelsen@hotmail.com
    ICQ# 47799046


  7. #7
    Member
    Join Date
    Jan 1999
    Location
    Garden Grove, CA, Orange
    Posts
    55

    Post

    U get an "Run-time Error: 380", cuz the procedure trying to set txtViewTable.SelLength to negative value when it didn't find matched item in the list.

    Try this

    Private Sub listTables_Click()
    txtViewTable.Text = listTables.Text
    End Sub

    Private Sub txtViewTable_Change()

    Dim x As Integer
    Dim i As Long

    x = Len(txtViewTable.Text)

    If x = 0 Then Exit Sub

    i = SendMessage(listTables.hWnd, LB_FINDSTRING, -1, ByVal txtViewTable.Text)
    If i > -1 Then
    listTables.ListIndex = i
    Else
    x = x - 1
    txtViewTable = Mid(txtViewTable, 1, x)
    listTables.ListIndex = SendMessage(listTables.hWnd, LB_FINDSTRING, -1, ByVal txtViewTable.Text)
    listTables_Click
    End If
    txtViewTable.SelStart = x
    txtViewTable.SelLength = Len(txtViewTable.Text) - x

    End Sub


    Joon

  8. #8

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Well, thank you all for your input, and thanks to the code example, jpark, I believe I know have it all working properly! Now I can celebrate! Thank you, all.

    ------------------
    Ryan
    cornelsen@hotmail.com
    ICQ# 47799046


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