Results 1 to 3 of 3

Thread: Search for Different String in a Text File

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    54

    Search for Different String in a Text File

    I need to search a Text File for Different Strings and accordingly I need to do different actions.

    Say,
    - if the test file has 'Login' and 'Failed' I should Say 'Login failed'
    - if the test file has 'JOB' then I should strip the next 4 character (for e.g., let
    us say it is 1234) and then Say 'JOB1234 Submitted'
    - if the test file has 'Login' and 'Password' I should Say 'Login Succeeded Change
    Your Password
    - if the test file has 'GoodBye' and 'Close' I should Say 'Connection Closed'


    How do I do this? The file would be pretty large sometime.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Search for Different String in a Text File

    How Large of a file? a few MB or 100's of MB??


    give this a shot: (off the top of my head)

    VB Code:
    1. Dim tmp As String
    2. Open "c:\Path\FileName.ext" For Input As #1
    3.     tmp = Input(LOF(1), 1)
    4. Close #1
    5.  
    6. If iInstr(tmp, "Login") And InStr(tmp, "Failed") Then
    7.     MsgBox "Login Failed"
    8. ElseIf InStr(tmp, "JOB") Then
    9.     MsgBox Mid(tmp, InStr(tmp, "JOB"), 7) & "Submitted"
    10. ElseIf iInstr(tmp, "Login") And InStr(tmp, "Password") Then
    11.     MsgBox "Login Succeeded Change your password"
    12. ElseIf iInstr(tmp, "GoodBye") And InStr(tmp, "Close") Then
    13.     MsgBox "Connection Closed"
    14. End If
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2005
    Posts
    54

    Re: Search for Different String in a Text File

    Thank You for your note [A51g]Static.

    I missed saying one thing. I apologize for that.

    The test file has 'Login' and 'Failed' and there is NO neccessity it would be in the same line.'Login' can be at the top of the file and 'failed' can be somehere in the middle or can be even at the Bottom of the File .But whereever those 2 words are found (regardless of where they are present anywhere across the file) I should Say 'Login failed' in a MsgBox
    Last edited by sakreg1; Oct 20th, 2005 at 03:17 AM.

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