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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextStream question

Status
Not open for further replies.

bakerm

Programmer
Apr 25, 2000
53
US
Is there a way to search for a string within a textstream object without going line by line?

I have tried using instr() and I get the following err:

Invalid procedure call or argument

Thanks!!!!
 
You need to read the data into a variable from the textstream. If you need to search for a string that crosses line boundaries (has an embedded newline in it), then you can use ReadAll() instead of ReadLine(). Then you can use the InStr() on that data.

Dim fso As New Scripting.FileSystemObject
Dim ts As Scripting.TextStream
Dim s As String
Dim n As Long

Set ts = fso_OpenTextFile(<file>)
s = ts.ReadAll
n = InStr(1, s, &quot;Value&quot;)

 
If the file isn't to big you could use File.ReadAll instead of File.ReadLine and then use the instr Function.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top