search in text file problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mse07
    New Member
    • Jan 2007
    • 36

    #1

    search in text file problems

    hi all

    i search about statement in text file by this code :


    Code:
    LineFlag = LineFlag + 1
          Line Input #1, strLine
    If LineFlag = 15 Then
            If InStr(1, strLine, " Transfer completed successfully.") <> 0 Then
                MsgBox "successful"
    
                Else
                MsgBox "failed", vbExclamation, ""
               End If
            End If
    but the problem some times the text file contains less than 15 lines and the program get out of if statement.

    i want search about statement without write the line number .
    i want the program search about statement in file without specified line number .

    example :

    the program search in text file about this statement : "Transfer completed successfully".
    if the program found this statement in any place in text file it shows message box .

    thank you
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    That's fairly simple. Just do the following...
    • Ignore the line number
    • After showing your "successful " msgbox, set a flag to say you did, then exit the loop.
    • Remove the Else clause
    • After the end of the loop, if your flag is not set, then show the "failed" msgbox.

    Comment

    • mse07
      New Member
      • Jan 2007
      • 36

      #3
      sorry
      can you explain this steps by code
      thank you

      Comment

      • kscmjo
        New Member
        • Mar 2007
        • 13

        #4
        There is no need to count lines if you are just looking for the end of file

        Code:
         
        do
              Line Input #1, strLine'
        loop until eof(#1)
        msgbox "File has ended"

        Comment

        Working...