这是MSDN的例子,看看能不能帮上忙吧!
Public Function FindMyText(ByVal searchText As String, ByVal searchStart As Integer, ByVal searchEnd As Integer) As Integer
' Initialize the return value to false by default.
Dim returnValue As Integer = -1
' Ensure that a search string and a valid starting point are specified.
If searchText.Length > 0 And searchStart >= 0 Then
' Ensure that a valid ending value is provided.
If searchEnd > searchStart Or searchEnd = -1 Then
' Obtain the location of the search string in richTextBox1.
Dim indexToText As Integer = richTextBox1.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase)
' Determine whether the text was found in richTextBox1.
If indexToText >= 0 Then
' Return the index to the specified search text.
returnValue = indexToText
End If
End If
End If
private sub findTxt(byval cTxt as string,optional byval lStart as long=-1,optional byval bFromBegin as boolean=true,optional byval bIgnoorUL as boolean = true)
dim I as long
dim J as integer
J=abs(cint(bIgnoorUL)
if bFromBegin then
if lStart=-1 then lStart=1
i=instr(lStart,text1.text,ctxt,J)
else
i=instrrev(text1.text,ctxt,lStart,J)
end if
if i<1 then
msgbox "找不到"
else
text1.selstart=I
text1.sellength=len(ctxt)
end if
end sub
没有调试,意思应该是这样的