如何VB中实现记事本中查找功能
1个回答
2013-11-04
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询