Results 1 to 2 of 2

Thread: VB Snippet - Autofill like Explorer Address Bar

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    VB Snippet - Autofill like Explorer Address Bar

    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias _
    2.     "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    3.     ByVal wParam As Long, lParam As Any) As Long
    4.  
    5. Const CB_FINDSTRING = &H14C
    6. Const CB_ERR = (-1)
    7.  
    8.  '*******************************************************************************
    9. ' AUTOFIND (FUNCTION)
    10. '
    11. ' DESCRIPTION:
    12. ' AUTOCOMPLETE A COMBOBOX (WORKS !!!)
    13.  '*******************************************************************************
    14.  
    15. Public Function AUTOFIND(ByRef cboCurrent As ComboBox, _
    16.     ByVal KeyAscii As Integer, Optional ByVal LimitToList As Boolean = False)
    17.    
    18.     Dim lCB As Long
    19.    
    20.     Dim sFindString As String
    21.    
    22.     If KeyAscii = 8 Then
    23.        
    24.         If cboCurrent.SelStart <= 1 Then
    25.            
    26.             cboCurrent = ""
    27.            
    28.             AUTOFIND = 0
    29.            
    30.             Exit Function
    31.            
    32.         End If
    33.        
    34.         If cboCurrent.SelLength = 0 Then
    35.            
    36.             sFindString = UCase(Left(cboCurrent, Len(cboCurrent) - 1))
    37.            
    38.         Else
    39.            
    40.             sFindString = Left$(cboCurrent.Text, cboCurrent.SelStart - 1)
    41.            
    42.         End If
    43.        
    44.     ElseIf KeyAscii < 32 Or KeyAscii > 127 Then
    45.        
    46.         Exit Function
    47.        
    48.     Else
    49.        
    50.         If cboCurrent.SelLength = 0 Then
    51.            
    52.             sFindString = UCase(cboCurrent.Text & Chr$(KeyAscii))
    53.            
    54.         Else
    55.            
    56.             sFindString = Left$(cboCurrent.Text, cboCurrent.SelStart) & Chr$(KeyAscii)
    57.            
    58.         End If
    59.        
    60.     End If
    61.    
    62.     lCB = SendMessage(cboCurrent.hwnd, CB_FINDSTRING, -1, ByVal sFindString)
    63.    
    64.     If lCB <> CB_ERR Then
    65.        
    66.         cboCurrent.ListIndex = lCB
    67.        
    68.         cboCurrent.SelStart = Len(sFindString)
    69.        
    70.         cboCurrent.SelLength = Len(cboCurrent.Text) - cboCurrent.SelStart
    71.        
    72.         AUTOFIND = 0
    73.        
    74.     Else
    75.        
    76.         If LimitToList = True Then
    77.            
    78.             AUTOFIND = 0
    79.            
    80.         Else
    81.            
    82.             AUTOFIND = KeyAscii
    83.            
    84.         End If
    85.        
    86.     End If
    87.    
    88. End Function
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  2. #2
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310
    Does it also work for DataCombo control?

    Thnx in advance

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