VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Begin finding in list box when you begin typing in Textbox Without any API use. Very easy and with

by Dipen Anovadia (19 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 7th April 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Begin finding in list box when you begin typing in Textbox Without any API use. Very easy and with only one procedure...!

API Declarations


Public Function IndexFromText(lb As ListBox, sFind As String, Optional bCaseSensitive As Boolean = False, Optional bMatchFull As Boolean = False, Optional bNoneOnBlank As Boolean = False, Optional lOUT_Error As Long = 0) As Long

On Error GoTo errIFT

Dim l As Long, lLen As Long
Dim s As String

IndexFromText = -2

If lb Is Nothing Then Exit Function
If lb.ListCount = 0 Then Exit Function

If sFind = "" Then
If bNoneOnBlank Then IndexFromText = -1
Exit Function
End If

lLen = Len(sFind)

For l = 0 To lb.ListCount - 1
s = lb.List(l)
If Len(s) >= lLen Then
If bCaseSensitive Then
If bMatchFull Then
If s = sFind Then
IndexFromText = l
Exit For
End If
Else
If Left(s, lLen) = sFind Then
IndexFromText = l
Exit For
End If
End If
Else
If bMatchFull Then
If UCase(s) = UCase(sFind) Then
IndexFromText = l
Exit For
End If
Else
If UCase(Left(s, lLen)) = UCase(sFind) Then
IndexFromText = l
Exit For
End If
End If
End If
End If
Next l

Exit Function
errIFT:
lOUT_Error = Err.Number
Err.Clear
IndexFromText = -3
End Function


Rate Begin finding in list box when you begin typing in Textbox Without any API use. Very easy and with



'Ensure all the objects are taken with proper names...
'such as-
'TextBox - txt               - textbox for testing
'ListBox - lst               - listbox for testing
'Command - btnClose          - button for closing app
'Check   - chkNoSelOnWrong   - checkbox for option-1
'Check   - chkResetOnBlank   - checkbox for option-2
'...
'Errors, feedbacks, etc...
'[email protected]
Private Sub Form_Load()

    Dim l As Long, b As Boolean

    lst.AddItem "Dipen"
    lst.AddItem "Tropix Game"
    lst.AddItem "Tropix Paradise"
    lst.AddItem "Daisy"
    lst.AddItem "MANDIP infotech"

    For l = 5 To 25
        b = Not b

        lst.AddItem IIf(b, l, "Dipen" & l)
    Next l
End Sub

Private Sub txt_Change()

    Dim lReturn As Long, lError As Long

    lReturn = IndexFromText(lst, txt, , , (chkResetOnBlank.Value And Checked), lError)

    If Not (lError = 0) Then Exit Sub

    If (chkNoSelOnWrong.Value And Checked) And lReturn = -2 Then lst.ListIndex = -1
    If lReturn < -1 Then Exit Sub
    If lReturn > lst.ListCount Then Exit Sub

    lst.ListIndex = lReturn
End Sub


Download this snippet    Add to My Saved Code

Begin finding in list box when you begin typing in Textbox Without any API use. Very easy and with Comments

No comments have been posted about Begin finding in list box when you begin typing in Textbox Without any API use. Very easy and with . Why not be the first to post a comment about Begin finding in list box when you begin typing in Textbox Without any API use. Very easy and with .

Post your comment

Subject:
Message:
0/1000 characters