|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Auto Finding in ComboBox ListI hope I have enough information presented here to make an answer easier to understand, than the "problem" is. I sure don't understand this process as it is now... I have a "State/Province" ComboBox, with a fairly long list of List-Elements. I wanted to have a function that would have a user enter just a portion of the State or Province, and the "function" would scan the list-elements and magically highlight the first list-element that matched... or not if the input didn't have a match. Someone has provided me with a sample that works, but as I try and integrate it into my application I will always get an overflow error with the first character entered in the ComboBox control. The "hint" provided by VB-6 is: Run Time error: '6': overflow I'm lost! The VB-6 "help file" says simply "An overflow results when you try to make an assignment that exceeds the limitations of the target of the assignment. " ( I don't know which part is the "assignment" is, or which part is the "target". The following is the process leading to my feeling so "duhhh". This first "Call" is made as soon as I enter the first character in the ComboBox. < Located in Form1 > Private Sub ComboBox1_KeyUp(Index As Integer, KeyCode As Integer, Shift As Integer) AutoFillCombo KeyCode, Shift, ComboBox1 End Sub < Located in ModGen > Option Explicit Global strCombo As String Global X% Global strTemp$ Global nRet& Const WM_SETREDRAW = &HB Const KEY_A = 65 Const KEY_Z = 90 Public Sub AutoFillCombo(KeyCode As Integer, Shift As Integer, cbX As ComboBox) If KeyCode >= KEY_A And KeyCode <= KEY_Z Then strTemp = cbX.Text If Len(strTemp) = 1 Then strCombo = strTemp nRet& = SendMessage(cbX.hWnd, WM_SETREDRAW, False, 0&) Fails on that last line. What could I be doing wrong?? Thanks, Paul ( persistence can be a disease ) Hi, I did that once (having an autocombo automatically complete the word)
but don't have it with me right now. I took a different approach for a new app, and worked as well as the previous one. What I did was: create a disconnected recordset with the information. Use the method rs.find, to retrieve the first record that matched the letters typed. As the user types, it finds the next match. If no match is found no autocomplete occurs. I call the rsfind methond on the onchange event of a textbox. Hope this helps. PS. I'll try to find the previous one that I used, that was with a combobox as yours. Paul Bruneau wrote:
Show quoteHide quote > If you have the assignment Value1 = Value2, then 'Value1' is the target.> I have a "State/Province" ComboBox, with a fairly long list of > List-Elements. I wanted to have a function that would have a user > enter just a portion of the State or Province, and the "function" > would scan the list-elements and magically highlight the first > list-element that matched... or not if the input didn't have a match. > > Someone has provided me with a sample that works, but as I try and > integrate it into my application I will always get an overflow error > with the first character entered in the ComboBox control. > The "hint" provided by VB-6 is: > > Run Time error: '6': > > overflow > > I'm lost! The VB-6 "help file" says simply > "An overflow results when you try to make an assignment that exceeds > the limitations of the target of the assignment. " ( I don't know > which part is the "assignment" is, or which part is the "target". This error message means that the Value1 variable cannot contain the size of the value in Value1. This would happen if they were declared: Dim iValue1 As Integer Dim lValue2 As Long .... and lValue2 was bigger than 32767 (the largest positive value you can put into an Integer type variable). I don't know how much computer science theory you know, but this is literally a processor integer overflow in this case. Show quoteHide quote > The following is the process leading to my feeling so "duhhh". This Gak! Where do these horrible code samples come from? I think your problems> first "Call" is made as soon as I enter the first character in the > ComboBox. > > < Located in Form1 > > Private Sub ComboBox1_KeyUp(Index As Integer, KeyCode As Integer, > Shift As Integer) > AutoFillCombo KeyCode, Shift, ComboBox1 > End Sub > > < Located in ModGen > > Option Explicit > Global strCombo As String > Global X% > Global strTemp$ > Global nRet& > Const WM_SETREDRAW = &HB > Const KEY_A = 65 > Const KEY_Z = 90 > > Public Sub AutoFillCombo(KeyCode As Integer, Shift As Integer, cbX As > ComboBox) If KeyCode >= KEY_A And KeyCode <= KEY_Z Then > strTemp = cbX.Text > If Len(strTemp) = 1 Then strCombo = strTemp > nRet& = SendMessage(cbX.hWnd, WM_SETREDRAW, False, 0&) > > Fails on that last line. > > What could I be doing wrong?? stems from using code written for VB3 in VB6. It still compiles, but there are subtle changes between these versions, one of which was that all 16 bit API calls (like SendMessage) are actually different from 32 bit API (Win32) calls. I take it that more code follow that last time - because all you are doing there is trying to prevent the combo box from updating as you continuously add new items to it. You've also not helped matters by not showing your declaration for the SendMessage() call. I would declare it as: Private Declare Function SendMessage Lib "User32.dll" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long You also shouldn't be using the VB 'False' value. In VB, True is a 16 bit integer evaluating to -1, and False is a 16 bit integer evaluating to 0. In the Win32 API, TRUE is a 32 bit unsigned integer evaluating to 1, and FALSE is a 32 bit unsigned integer evaluating to 0. To be absolutely safe, I would create two constants: Private Const API_FALSE As Long = 0 Private Const API_TRUE As Long = 1 ... and use these values from than False and True when using WM_SETREDRAW. Finally, and this is not only a stylistic choice but a good habit to get into, don't use Global - use Public; and don't declare variables using type declaration suffices i.e. %&$!# - use As Integer, As String etc. Hope this helps. -- Mark Bertenshaw Kingston upon Thames UK |
|||||||||||||||||||||||