Visual Basic > API and Miscellaneous
Implementing Find Functionality
Implementing Find Functionality Private Function FindInTextBox(TheTextBox As TextBox, _ StringToFind As String, Settings As Byte) As Long 'First dimension some variables. Dim SearchText As String Dim Count As Long Dim Direction As Integer Dim StartPos As Long Dim EndPos As Long 'We put the TextBox's content in a string for 'faster access. SearchText = TheTextBox.Text 'Then decide what we have to do. If Settings = 0 Then StartPos = 1 EndPos = Len(TheTextBox.Text) Direction = 1 ElseIf Settings = 1 Then StartPos = TheTextBox.SelStart + 1 EndPos = Len(TheTextBox.Text) Direction = 1 Else 'Settings = 2 StartPos = TheTextBox.SelStart - 1 EndPos = 1 Direction = -1 End If 'Loop through finding the text. For Count = StartPos To EndPos Step Direction If Mid$(SearchText, Count, Len(StringToFind)) = StringToFind Then TheTextBox.SelStart = Count - 1 TheTextBox.SelLength = Len(StringToFind) FindInTextBox = Count - 1 Exit Function End If Next Count 'If it isn't found, return 0. FindInTextBox = 0 End Function
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows