|
-
Oct 19th, 2005, 10:18 AM
#1
Thread Starter
Member
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.
-
Oct 19th, 2005, 10:26 AM
#2
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:
Dim tmp As String
Open "c:\Path\FileName.ext" For Input As #1
tmp = Input(LOF(1), 1)
Close #1
If iInstr(tmp, "Login") And InStr(tmp, "Failed") Then
MsgBox "Login Failed"
ElseIf InStr(tmp, "JOB") Then
MsgBox Mid(tmp, InStr(tmp, "JOB"), 7) & "Submitted"
ElseIf iInstr(tmp, "Login") And InStr(tmp, "Password") Then
MsgBox "Login Succeeded Change your password"
ElseIf iInstr(tmp, "GoodBye") And InStr(tmp, "Close") Then
MsgBox "Connection Closed"
End If
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Oct 20th, 2005, 03:04 AM
#3
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|