vb查找制定文本功能

来源:百度知道 编辑:UC知道 时间:2024/06/12 02:32:39
有一个文本框里面有内容
点击窗体时候 弹出对话框输入要查找的字符
点击确定按钮 文本框被找到的字符被涂黑显示
若文本框没有被找到的字符 则弹出对话框提示 没找到
师傅 我不懂得这个怎么写代码?

Private Sub Form_Click()
Dim sStr As String
Dim nStart As Integer
Dim nlen As Integer
sStr = InputBox("请输入要查找的内容:", "查找")
nlen = Len(Trim(sStr))
If nlen > 0 Then
nStart = InStr(1, Trim(Text1.Text), Trim(sStr), vbTextCompare)
If nStart > 0 Then
Text1.SelStart = nStart - 1
Text1.SelLength = nlen

Else
MsgBox "你查找的内容不存在"
End If
Else
Text1.SelStart = 0
Text1.SelLength = 0
End If
End Sub