by Muhammad Musa Ali (6 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 19th November 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Combo box - auto fills the combo box from the list as you type in - I had placed the following code snippet in two parts. A lot of people were
'Just call the Procedure in the Combobox_Change event like
'Private Sub cboEvaluators_Change()
' Call Proc_ComboAutoFill(cboEvaluators)
'End Sub
' where cboEvaluators is the combo box filled with a list of items
Public Sub Proc_ComboAutoFill(cboCtl As Control)
Dim i As Integer
Dim szEntry As String
If cboCtl.SelStart = 0 Then
szEntry = cboCtl.Text
Else
szEntry = Left$(cboCtl.Text, cboCtl.SelStart)
End If
If IsNull(szEntry) Then Exit Sub
If cboCtl.ListCount = 0 Then Exit Sub
Do
i = Func_BinaryListSearch(cboCtl, szEntry)
If i <> -1 Then
cboCtl.ListIndex = i
cboCtl.SelStart = Len(szEntry)
cboCtl.SelLength = Len(cboCtl.List(i)) - Len(szEntry)
Exit Sub
Else
If Len(szEntry) <= 1 Then
cboCtl.ListIndex = 0
Exit Sub
Else
szEntry = Left$(szEntry, Len(szEntry) - 1)
End If
End If
Loop
End Sub
Public Function Func_BinaryListSearch(ctlList As Control, szSearch As String) As Integer
Dim MidPt As Integer
Dim LoPt As Integer
Dim HiPt As Integer
Dim CmpVal As Integer
LoPt = 0
HiPt = ctlList.ListCount
Do While LoPt < HiPt
MidPt = LoPt + (HiPt - LoPt) \ 2
CmpVal = StrComp(UCase$(Left$(ctlList.List(MidPt), Len(szSearch))), UCase$(szSearch))
If CmpVal = 0 Then
Exit Do
ElseIf CmpVal = 1 Then
HiPt = MidPt
Else
LoPt = MidPt + 1
End If
Loop
If CmpVal = 0 Then
Do
MidPt = MidPt - 1
If MidPt < 0 Then
MidPt = 0
Exit Do
End If
If UCase$(Left$(ctlList.List(MidPt), Len(szSearch))) <> UCase$(szSearch) Then
MidPt = MidPt + 1
Exit Do
End If
Loop
Else
MidPt = -1
End If
Func_BinaryListSearch = MidPt
End Function
No comments have been posted about Combo box - auto fills the combo box from the list as you type in - I had placed the following code. Why not be the first to post a comment about Combo box - auto fills the combo box from the list as you type in - I had placed the following code.