请教一个查找替换的问题?
为什么我写的这段代码,要按那个查找好几次,它才会跳到下一个查找的目标啊???请指教下谢谢!!
我的代码是:n 为全局变量。
Public Sub FindText(ByVal te As String)
Dim pos As Integer
Dim target As String
target = te.Length()
pos = InStr(n, Form1.RichTextBox1.Text(), te)
If pos > 0 Then
MyPos = pos - 1
Form1.RichTextBox1.SelectionStart = MyPos
Form1.RichTextBox1.SelectionLength = Len(target)
Form1.RichTextBox1.Focus()
n += 1
Else
MsgBox("查找完毕!")
n = 1
End If
End Sub