高分寻高手! vb 文字查找

来源:百度知道 编辑:UC知道 时间:2024/06/22 11:42:08
以前获得过代码是有个:Text1(文本1)
Text2(文本2)
command1(查找按钮)
(继续查找按钮)
在Text1中的属性设置好文本,在Text2内输入关键字后点击“查找”按钮Text1就会自动选中被查找字体;如果要继续查找的话点击command2可以自动选中下一个;修改关键字可自动从顶部开始搜索,如果没有出现提示框“没有找到!”
我把代码给弄丢了~~~~ 哭死啊~~!!哪位大哥帮帮忙!小弟在这感激不尽!!!

Option Explicit
Dim number As Long

Private Function FindStr(ByVal SLeft As Long, ByVal SFind As String, ByVal SSFind As String)
If Len(SFind) > Len(SSFind) - SLeft Then
FindStr = -1
Exit Function
Else
FindStr = InStr(SLeft + 1, SSFind, SFind) - 1
End If
End Function

Private Sub Form_Load()
Command2.Enabled = False
End Sub

Private Sub Command1_Click()
number = FindStr(0, Text1.Text, Text2.Text)
If number = -1 Then
MsgBox "没有找到"
Command2.Enabled = False
Else
Text2.SelStart = number
Text2.SelLength = Len(Text1.Text)
Command2.Enabled = True
End If
End Sub

Private Sub Command2_Click()
number = FindStr(number + Len(Text1.Text), Text1.Text, Text2.Text)
If number = -1 Then
MsgBox "查找完毕"
Command2.Enabled = False
Else
Text2.SelStart