Is there any way to search through a text file for a string matching the string in a text box using FSO?
Printable View
Is there any way to search through a text file for a string matching the string in a text box using FSO?
Why do you need to use the FSO? Try this:VB Code:
Private Sub FindTextInFile(sStringToFind As String, sFileToLookIn As String) Dim arrLinesArray() As String Dim i As Long Dim bIsItThere As Boolean 'read file into array of lines Open sFileToLookIn For Binary As #1 arrLinesArray = Split(Input(LOF(1), #1), vbCrLf) Close #1 'search array line by line for text bIsItThere = False For i = LBound(arrLinesArray) To UBound(arrLinesArray) If InStr(arrLinesArray(i), sStringToFind) > 0 Then bIsItThere = True 'found it Exit For End If Next 'let them know whats going on If bIsItThere = True Then MsgBox "The string " & sStringToFind & " was found on line: " & i & " in " & UCase(sFileToLookIn) Else MsgBox "The string " & sStringToFind & " was not found in " & UCase(sFileToLookIn) End If End Sub Private Sub Command1_Click() Call FindTextInFile("StringToFind", "c:\FileToFindItIn.txt") End Sub
I can't find any documentation on FSO having a search method.Quote:
Originally Posted by GamerMax5
That certainly would be appropriate. I would imagine it's coming down the pike eventually - I've seen info about FSO being enhanced further in the future.