-
This searches a text box. How can i get it to continue searching for the next words if it doesn't find a result?
Private Sub Command5_Click()
selct
copy
pste
Dim objSearch As Collection
Dim varSearch As Variant
Dim intPos As Integer
Set objSearch = New Collection
objSearch.Add "ccc"
objSearch.Add "aurora"
objSearch.Add "mining"
intPos = 0
For Each varSearch In objSearch
intPos = InStr(1, Text1.Text, varSearch)
If intPos > 0 Then
Open "C:\File.txt" For Append As #1
Print #1, varSearch & " was found in (" & _
Text1.Text & ") at position " & intPos
Close #1
Else
MsgBox "no results"
End If
Next
End Sub
-
This works for me Beacon, I have replaced the collection for an array for performance:
Code:
Private Sub Command1_Click()
Dim Search(2) As String
Dim i As Integer
Dim intPos As Integer
Search(0) = "ccc"
Search(1) = "aurora"
Search(2) = "mining"
intPos = 0
For i = 0 To UBound(Search)
intPos = InStr(1, Text1.Text, Search(i))
If intPos > 0 Then
Open "C:\File.txt" For Append As #1
Print #1, Search(i) & " was found In (" & _
Text1.Text & ") at position " & intPos
Close #1
Else
msgbox search(i) & "not found."
End If
Next i
End Sub