Public po As Long Function find(key As String, Text1 As TextBox) s = Text1.Text t = key Indexs = InStr(po, s, t) If Indexs > 0 Then With Text1 .SelStart = Indexs - 1 .SelLength = Len(t) .SetFocus End With po = Indexs + 1 Else MsgBox "没有找到你寻求的串" po = 1 End If End FunctionPrivate Sub Command1_Click() t = find("an", Text1) End SubPrivate Sub Form_Load() po = 1 End SubPrivate Sub Text1_Change() po = 1 End Sub
Function find(key As String, Text1 As TextBox)
s = Text1.Text
t = key
Indexs = InStr(po, s, t)
If Indexs > 0 Then
With Text1
.SelStart = Indexs - 1
.SelLength = Len(t)
.SetFocus
End With
po = Indexs + 1
Else
MsgBox "没有找到你寻求的串"
po = 1
End If
End FunctionPrivate Sub Command1_Click()
t = find("an", Text1)
End SubPrivate Sub Form_Load()
po = 1
End SubPrivate Sub Text1_Change()
po = 1
End Sub