VB 查找字符串出现的位置
我用下面的代码查找指定的字符串,Richtextbox里面一共有8173行的内容,我要查找的字符串分别在第7520行和8173行,但是当我点第二次搜索时,出现错误“实时错...
我用下面的代码查找指定的字符串,Richtextbox里面一共有8173行的内容,我要查找的字符串分别在第7520行和8173行,但是当我点第二次搜索时,出现错误“实时错误 6: 溢出”。点击“调试”错误出现在"findtext targetposition + 1"
Private targetposition As Long
Dim i As Integer
Private Sub findtext(ByVal start_at As Integer)
Dim pos As Long
Dim target As String
target = txtSearch.Text
pos = InStr(start_at, Richtextbox1.Text, target)
If pos > 0 Then
targetposition = pos
Richtextbox1.SelStart = targetposition - 1
Richtextbox1.SelLength = Len(target)
Richtextbox1.SetFocus
Else
MsgBox "Last one"
i = 0
End If
End Sub
Private Sub Command1_Click()
If Text1.Text = "" Then
i = 1
Else
i = i + 1
End If
If i < 2 Then
findtext 1
Else
findtext targetposition + 1
End If
End Sub
点第一次可以搜索到第7520行的,但是点第二次搜索时,就会出错。 展开
Private targetposition As Long
Dim i As Integer
Private Sub findtext(ByVal start_at As Integer)
Dim pos As Long
Dim target As String
target = txtSearch.Text
pos = InStr(start_at, Richtextbox1.Text, target)
If pos > 0 Then
targetposition = pos
Richtextbox1.SelStart = targetposition - 1
Richtextbox1.SelLength = Len(target)
Richtextbox1.SetFocus
Else
MsgBox "Last one"
i = 0
End If
End Sub
Private Sub Command1_Click()
If Text1.Text = "" Then
i = 1
Else
i = i + 1
End If
If i < 2 Then
findtext 1
Else
findtext targetposition + 1
End If
End Sub
点第一次可以搜索到第7520行的,但是点第二次搜索时,就会出错。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询