PDA

Click to See Complete Forum and Search --> : text box question


Gimpster
Dec 28th, 1999, 12:54 AM
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:
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 (http://www.ICQ.com)# 47799046



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

Yonatan
Dec 28th, 1999, 01:04 AM
Dim X As STRING ?
Try Long...

------------------
Yonatan
Teenage Programmer
E-Mail: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)
AIM: RYoni69

Gimpster
Dec 28th, 1999, 01:20 AM
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 (http://www.ICQ.com)# 47799046

Serge
Dec 28th, 1999, 06:00 AM
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 (http://www.icq.com/51055819)

MartinLiss
Dec 28th, 1999, 10:23 AM
I believe that if you add txtViewTable.Text = listTables.Text to the listTables_Click() event, that it will fix your problem.

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

Gimpster
Dec 29th, 1999, 02:04 AM
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 (http://www.ICQ.com)# 47799046

jpark
Dec 29th, 1999, 03:44 AM
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

Gimpster
Dec 29th, 1999, 04:50 AM
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 (http://www.ICQ.com)# 47799046