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.
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
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