Results 1 to 2 of 2

Thread: Continue Searching

  1. #1

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    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

  2. #2
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width