Hello All
I have a script that searches a text file for a username that i enter into an input box. It then finds those matching entries and writes them to another text file.
This works fine. But i end up with lots of entries matching the search criteria. All i want is the last entry that it finds. How can i just choose the last entry to be shown!? I have looked into search from the end of the file but i dont know how to impliment just capturing the one entry and finishing.
Here is my script that works:
'Set Constants
Const ForReading = 1
Const ForWriting = 2
Input = InputBox("Enter the Username to Search For")
strSearch = Input
'Open the TXT file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\Audit.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strLine = objTextFile.ReadLine
intUser = InStr(strLine, StrSearch)
If intUser > 0 Then
strNewText = strNewText & strLine & VbCrLf
End If
Loop
objTextFile.Close
Set objTextFile = objFSO.OpenTextFile _
("C:\test.txt", ForWriting)
objTextFile.Write(strNewText)
objTextFile.Close
Any help on this would be appreciated.
Rob
I have a script that searches a text file for a username that i enter into an input box. It then finds those matching entries and writes them to another text file.
This works fine. But i end up with lots of entries matching the search criteria. All i want is the last entry that it finds. How can i just choose the last entry to be shown!? I have looked into search from the end of the file but i dont know how to impliment just capturing the one entry and finishing.
Here is my script that works:
'Set Constants
Const ForReading = 1
Const ForWriting = 2
Input = InputBox("Enter the Username to Search For")
strSearch = Input
'Open the TXT file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\Audit.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strLine = objTextFile.ReadLine
intUser = InStr(strLine, StrSearch)
If intUser > 0 Then
strNewText = strNewText & strLine & VbCrLf
End If
Loop
objTextFile.Close
Set objTextFile = objFSO.OpenTextFile _
("C:\test.txt", ForWriting)
objTextFile.Write(strNewText)
objTextFile.Close
Any help on this would be appreciated.
Rob