Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search does not work

Status
Not open for further replies.

marshyrob

Technical User
Jan 20, 2004
137
GB
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
 
You may consider the InStr function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV

Thanks for the repy, its much appreciated. Can you give anymore direction on that function, a link or something i can use for reference. Im trying to learn VB (very slowly!) so any helpful hints would be great.

Rob
 
Thanks PHV ill have a look and see if i can work it all out!

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top