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

Finding a string in a file

Status
Not open for further replies.

shultz

Programmer
Oct 28, 2001
42
HK
Hi,

To find a string in another string I use the function

InStr(1, txtLine, "Not Found", vbTextCompare)

Is there a function to find whether a particular string exists or not in a specified file. I want to give a txt file(or any other file) as input and find out for the existance of the string.

thanks a lot.
 
Hi,
Can't you just read all the data in the file into a string variable and search that text string using InStr? Hope it helps. Let me know what happens.
With regards,
PGK
 

Dim iFileNum As Integer
Dim str As String
iFileNum = FreeFile

Open "C:\myFile.Txt" For Input As #iFileNum

str = Input(LOF(iFileNum), #iFileNum)

Close #iFileNum

'Return position if text is found
Debug.Print InStr(1, str, "FindThisText", vbTextCompare)
[/b][/i][/u]*******************************************************[sub]
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top