Hi all
Can anyone give me a little help.
Im trying to search a txt file from the bottom up for a specified username (input box), then when found i want it to write the resulting line that the username is in to another txt file.
Here is the code that runs but does not produce anything, i know its not going to write the whole line at the moment but i dont know VB very well so im just glueing it together from things i can find. (which is why im going wrong!)
Dim arrFileLines()
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Audit.txt", 1)
StrInput = InputBox("Enter the Username")
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
If arrFileLines(l) = StrInput then
Set objFile = objFSO.OpenTextFile("C:\Results.txt", ForWriting)
objFile.Write arrFileLines(l)
objFile.Close
End If
Next
Any help would be appreciated.
Rob
Can anyone give me a little help.
Im trying to search a txt file from the bottom up for a specified username (input box), then when found i want it to write the resulting line that the username is in to another txt file.
Here is the code that runs but does not produce anything, i know its not going to write the whole line at the moment but i dont know VB very well so im just glueing it together from things i can find. (which is why im going wrong!)
Dim arrFileLines()
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Audit.txt", 1)
StrInput = InputBox("Enter the Username")
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
If arrFileLines(l) = StrInput then
Set objFile = objFSO.OpenTextFile("C:\Results.txt", ForWriting)
objFile.Write arrFileLines(l)
objFile.Close
End If
Next
Any help would be appreciated.
Rob