Dim n As Long, chazhao As String
Private Sub Command1_Click()'这段代码为查找
Dim s As String
s = Text1.Text
chazhao = InputBox("")
If chazhao = "" Then
MsgBox "空字符串不能查找"
Exit Sub
End If
n = InStr(s, chazhao)
If n > 0 Then
Text1.SelStart = n - 1
Text1.SelLength = Len(chazhao)
Text1.SetFocus
Else
MsgBox "不包含所查找的字符串"
End If
End Sub
Private Sub Command2_Click()'这段代码为查找下一个
Dim s As String, linshi As Long
If chazhao = "" Then
chazhao = InputBox("")
If chazhao = "" Then
MsgBox "空字符串不能查找"
Exit Sub
End If
End If
If n = 0 Then
s = Text1.Text
Else
s = Mid(Text1.Text, n + Len(chazhao), Len(Text1.Text) - n - Len(chazhao))
End If
linshi = n
n = InStr(s, chazhao)
If n > 0 Then
n = n + linshi
Text1.SelStart = n - 1
Text1.SelLength = Len(chazhao)
Text1.SetFocus
Else
If linshi <> 0 Then
MsgBox "没有相似的了"
End If
End If
End Sub
温馨提示:答案为网友推荐,仅供参考