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 certain words in a text file? 1

Status
Not open for further replies.

Agent009

Programmer
Apr 4, 2003
96
IE
hi all,

I have started an new VB application today

I have to search a text file(notepad file) for certain words i.e an error using the application

If a particualar word is found in this text file i want to copy the entire line of text it is on and its following line and copy them into another text file named "errors found" or something like that. I know where the file to be searched and the errors file are so how do i find the errors?

How is this done? I am am quite inexperienced in VB so any help is gratefully accepted!

"Be excellent to each other"

Agent009,
 
Try this :

Dim i As Long
Dim strFilename As String
Dim strIn As String
Dim arrIn() As String
Dim strTemp As String

i = FreeFile
strFilename = "\TextFile.txt"

Open strFilename For Input As #i
Do While Not EOF(i)
Line Input #i, strIn
'look for your error in strIn

Loop
Close #i


Exit Sub
ErrorHandler:
StatusNormal
gobjErr.ShowError "Configuration.Startup"

End Sub

 
Try this :


mFileOutput = FreeFile
Open "c:\Errors.txt" For Append Shared As #mFileHandle


i = FreeFile
strFile = "c:\TextFile.txt"

Open strFilename For Input As #i
Do While Not EOF(i)
Line Input #i, strIn
'look for your error in strIn
Print FileHandle,strIn
Loop
Close #i



 
Seems an ideal candidate for a Regular Expressions solution...
 
Ok i have the search looking for a particular string in my text file:

Dim i As Long
Dim strFilename As String
Dim strIn As String
Dim arrIn() As String
Dim strTemp As String
Dim iLines As Integer
Dim count As Integer

iLines = 0
count = 0

i = FreeFile
strFilename = (App.Path + "\Test.txt")

Open strFilename For Input As #i
Do While Not EOF(i)
Line Input #i, strIn
'look for your error in strIn,
If strIn = "11111111" Then
MsgBox ("File Found")

End If

Loop

Close #i

What i want to do next is then copy this file "11111111" into another file called "Error.text". how is this done?

Also, while the search is running i have added a progression bar onto my form, how do i make this work and grow more and more every time the loop runs?

thanks,

"We are wyld stallyns"
 
Ok i have the search looking for a particular string in my text file:

Dim i As Long
Dim strFilename As String
Dim strIn As String
Dim arrIn() As String
Dim strTemp As String
Dim iLines As Integer
Dim count As Integer

iLines = 0
count = 0

i = FreeFile
strFilename = (App.Path + "\Test.txt")

Open strFilename For Input As #i
Do While Not EOF(i)
Line Input #i, strIn
'look for your error in strIn,
If strIn = "11111111" Then
MsgBox ("File Found")

End If

Loop

Close #i

What i want to do next is then copy this file "11111111" into another file called "Error.text", once the search has ended. how is this done?

Also, while the search is running i have added a progression bar onto my form, how do i make this work and grow more and more every time the loop runs?

thanks,

"We are wyld stallyns"
 
Whats the OR condition in VB?

if a == true OR b == true
then...

is that how its done, or is it

if a==true || b == true
then...
 
How do i add the error to another file error.txt?

 

mFile = FreeFile
Open "c:\error.txt" strPath For Append Shared As #mFileHandle


Print mFileHandle, "Error"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top