Rabu, Januari 10, 2007

Auto Complete pada ComboBox

' Name: a AutoComplete Very Simple!
' Description:VERY SIMPLE cut and paste
' funtion for the Keypress event of a comb
' obox. Just paste this code into a module
' or form and call the function from the K
' eyPress event. KeyAscii = AutoComplete(c
' boCombobox, KeyAscii,Optional UpperCase)
' By: J.R. Berard
'This code is copyrighted and has' limited warranties.Please see http://w
' ww.Planet-Source-Code.com/vb/scripts/Sho
' wCode.asp?txtCodeId=43911&lngWId=1'for details.'

Option Explicit
Public Const CB_FINDSTRING = &H14C

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long,
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Function AutoComplete(cbCombo As ComboBox, sKeyAscii As Integer,
Optional bUpperCase As Boolean = True) As Integer

Dim lngFind As Long, intPos As Integer, intLength As Integer
Dim tStr As String

With cbCombo

If sKeyAscii = 8 Then
If .SelStart = 0 Then Exit Function
.SelStart = .SelStart - 1
.SelLength = 32000
.SelText = ""
intPos = .SelStart '// save intial cursor position
tStr = .Text '// save String

If bUpperCase = True Then
.SelText = UCase(Chr(sKeyAscii)) '// change string. (uppercase only)
.SelText = UCase(Chr(sKeyAscii)) '// change string. (leave case alone)
End If
End If

lngFind = SendMessage(.hwnd, CB_FINDSTRING, 0, ByVal .Text) '// Find string in combobox

If lngFind = -1 Then '// if String Not found
.Text = tStr '// Set old String (used For boxes that require charachter monitoring
.SelStart = intPos '// Set cursor position
.SelLength = (Len(.Text) - intPos) '// Set selected length
AutoComplete = 0 '// return 0 value to KeyAscii
Exit Function

Else '// If String found
intPos = .SelStart '// save cursor position
intLength = Len(.List(lngFind)) - Len(.Text) '// save remaining highlighted text length
.SelText = .SelText & Right(.List(lngFind), intLength) '// change new text in String
'.Text = .List(lngFind)'// Use this inst
' ead of the above .Seltext line to set th
' e text typed to the exact case of the it
' em selected in the combo box.
.SelStart = intPos '// Set cursor position
.SelLength = intLength '// Set selected length
End If
End With

End Function

1 komentar:

Anonim mengatakan...

Emancipation Our Inadequate Prices at www.Pharmashack.com, The Prominent [b][url=http://www.pharmashack.com]Online Chemist's acquiring [/url][/b] To [url=http://www.pharmashack.com]Buy Viagra[/url] Online ! You Can also Board shocking Pre-eminent Deals When You [url=http://www.pharmashack.com/en/item/cialis.html]Buy Cialis[/url] and When You You [url=http://www.pharmashack.com/en/item/levitra.html]Buy Levitra[/url] Online. We Also Be subjected to a Ingenious Generic [url=http://www.pharmashack.com/en/item/phentermine.html]Phentermine[/url] On account of Your Victuals ! We Paraphernalia Type [url=http://www.pharmashack.com/en/item/viagra.html]Viagra[/url] and Also [url=http://www.pharmashack.com/en/item/generic_viagra.html]Generic Viagra[/url] !