• Welcome to Valhalla Legends Archive.
 

Autocomplete

Started by -kP-FuZioN, July 10, 2003, 10:02 PM

Previous topic - Next topic

-kP-FuZioN

I'm using vb 6 and I want to make some sort of mechanism for autocomplete, like the ones where you type the first part, and then the rest of the word is filled in, but highlighted.  I don't know how to highlight things on text boxes.  Can someone help me out?

iago

To highlight, say, the first 5 characters, use this:
text1.selstart = 5
text1.sellength = len(text1.text) - 5
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


dxoigmn

Quote from: iago on July 11, 2003, 07:10 AM
To highlight, say, the first 5 characters, use this:
text1.selstart = 5
text1.sellength = len(text1.text) - 5



Wouldn't that highlight all the characters after the 5th one?

DarkMinion

Yes, selstart should be 0, and sellength should be just 5 if you want the first 5 characters....

iago

That's what I meant to say.. my bad :)
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


ioSys

Mail me and i can send you the code for it. its not that hard. [email protected]

TheMinistered

Here is a combo box autocomplete from extreme vb code library:

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 CB_FINDSTRING As Long = &H14C

Public Sub ComboAutoComplete(ByRef SourceCtl As VB.ComboBox, _
   ByRef KeyAscii As Integer, ByRef LeftOffPos As Long)
 Dim iStart As Long
 Dim sSearchKey As String
 
 With SourceCtl
   'If text entered so far matches item(s) in the list, use autocomplete
   Select Case Chr$(KeyAscii)
     Case vbBack
       'Let backspace characters process as usual; otherwise try to match text
     Case Else
       If Chr$(KeyAscii) <> vbBack Then
         .SelText = Chr$(KeyAscii)
         
         iStart = .SelStart
         
         If LeftOffPos <> 0 Then
           .SelStart = LeftOffPos
           iStart = LeftOffPos
         End If
         
         sSearchKey = CStr(Left$(.Text, iStart))
         .ListIndex = SendMessage(.hWnd, CB_FINDSTRING, -1, _
             ByVal CStr(Left$(.Text, iStart)))
         
         If .ListIndex = -1 Then
           LeftOffPos = Len(sSearchKey)
         End If
         
         .SelStart = iStart
         .SelLength = Len(.Text)
         LeftOffPos = 0
         
         KeyAscii = 0
       End If
   End Select
 End With
End Sub

Private Sub Combo1_KeyPress(KeyAscii As Integer)
 Static iLeftOff As Long
 
 ComboAutoComplete Combo1, KeyAscii, iLeftOff
End Sub