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 没有调试,意思应该是这样的
To cuizm(射天狼): 我用的是RICHTEXTBOX,请问查找函数到哪里去找?
这是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
从字符串"AAAABBAAA"的第一个字符开始查找字符"BB"
lPos=Instr(1,"AAAABBAAABBAA","BB")
返回lPos=5
再调用一次
lPos=Instr(lPos+1,"AAAABBAAABBAA","BB")
返回lPos=10
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
没有调试,意思应该是这样的
我用的是RICHTEXTBOX,请问查找函数到哪里去找?
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