Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleFind a string within a TextBox
Keywordsfind string, find text, find, search, TextBox
CategoriesStrings, Controls
 
Use the InStr Function.
 
Private TargetPosition As Integer

Private Sub FindText(ByVal start_at As Integer)
Dim pos As Integer
Dim target As String

    target = txtTarget.Text
    pos = InStr(start_at, txtBody.Text, target)
    If pos > 0 Then
        ' We found it.
        TargetPosition = pos
        txtBody.SelStart = TargetPosition - 1
        txtBody.SelLength = Len(target)
        txtBody.SetFocus
    Else
        ' We did not find it.
        MsgBox "Not found."
        txtBody.SetFocus
    End If
End Sub

' Find the text.
Private Sub cmdFind_Click()
    FindText 1
End Sub

' Find the next occurrance of the text.
Private Sub cmdFindNext_Click()
    FindText TargetPosition + 1
End Sub
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated