This works!!! to where my strToFind will find my "SHT"
but only one instance.. I have a text document with many instances of "SHT".in the line of text and I want them all this code gives me just one when I click to transfer into my selected file..
also how can I add more acronyms like "SHT" to find ( for example SP,DAVE,TOM, ECT
these are the ways i have tryed it....
strTofind = "SHT,DAVE,ECT" !deos not work!
strtofind = "sht", "dave", "ect" !does not work!
strtofind = "sht" "dave" "ect" !does not work!
strtofind = ("sht", "dave", "ect") !does not work!
strtofind = ("sht, "dave, ect") !does not work!
so I need to know how to add more acronyms that would be in my text file?
and to extract all instances of selected acronyms?
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ofd4.ShowDialog()
If Not Me.txtFile.Text = "close" Then
Dim instance As COMException
' Set this to the file to search
strInputFile = Me.txtFile.Text
' Set this to the new file to create
strOutputFile = (ofd4.FileName)
' Set the specific text to search for
strTextToFind = "SHT"
line1 = "SR"
'line2 = "PL"
' Set this to determine whether to match with case sensitivity
boolMatchCaseSensitive = True
objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Const intForWriting = 2
Const intForAppending = 8
objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
strFoundText = "&"
' Read the first line if the file is not empty
While Not objInputFile.AtEndOfStream
strLine = objInputFile.ReadLine
If boolMatchCaseSensitive = False Then
If InStr(LCase(strLine), LCase(strTextToFind)) > 0 Then strFoundText = strLine
Else
If InStr(strLine, strTextToFind) > 0 Then strFoundText = strLine
'If InStr(LCase(strLine), LCase(line1)) > 0 Then strFoundText = strLine
'If InStr(strLine, line1) > 0 Then strFoundText = strLine
End If
End While
objInputFile.Close()
objInputFile = Nothing
If strFoundText <> "" Then
objOutputFile = objFSO.OpenTextFile(strOutputFile, intForAppending, True)
objOutputFile.WriteLine(strFoundText)
objOutputFile.Close()
objOutputFile = Nothing
objFSO = Nothing
MsgBox(" Added to Burn Cut Sheet")
Else
MsgBox(strTextToFind & vbCrLf & "was not found in" & strInputFile)
End If
Timer1.Start()
Timer1.Enabled = False
Else
MessageBox.Show("Please select a file.")
End If
End Sub
but only one instance.. I have a text document with many instances of "SHT".in the line of text and I want them all this code gives me just one when I click to transfer into my selected file..
also how can I add more acronyms like "SHT" to find ( for example SP,DAVE,TOM, ECT
these are the ways i have tryed it....
strTofind = "SHT,DAVE,ECT" !deos not work!
strtofind = "sht", "dave", "ect" !does not work!
strtofind = "sht" "dave" "ect" !does not work!
strtofind = ("sht", "dave", "ect") !does not work!
strtofind = ("sht, "dave, ect") !does not work!
so I need to know how to add more acronyms that would be in my text file?
and to extract all instances of selected acronyms?
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ofd4.ShowDialog()
If Not Me.txtFile.Text = "close" Then
Dim instance As COMException
' Set this to the file to search
strInputFile = Me.txtFile.Text
' Set this to the new file to create
strOutputFile = (ofd4.FileName)
' Set the specific text to search for
strTextToFind = "SHT"
line1 = "SR"
'line2 = "PL"
' Set this to determine whether to match with case sensitivity
boolMatchCaseSensitive = True
objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Const intForWriting = 2
Const intForAppending = 8
objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
strFoundText = "&"
' Read the first line if the file is not empty
While Not objInputFile.AtEndOfStream
strLine = objInputFile.ReadLine
If boolMatchCaseSensitive = False Then
If InStr(LCase(strLine), LCase(strTextToFind)) > 0 Then strFoundText = strLine
Else
If InStr(strLine, strTextToFind) > 0 Then strFoundText = strLine
'If InStr(LCase(strLine), LCase(line1)) > 0 Then strFoundText = strLine
'If InStr(strLine, line1) > 0 Then strFoundText = strLine
End If
End While
objInputFile.Close()
objInputFile = Nothing
If strFoundText <> "" Then
objOutputFile = objFSO.OpenTextFile(strOutputFile, intForAppending, True)
objOutputFile.WriteLine(strFoundText)
objOutputFile.Close()
objOutputFile = Nothing
objFSO = Nothing
MsgBox(" Added to Burn Cut Sheet")
Else
MsgBox(strTextToFind & vbCrLf & "was not found in" & strInputFile)
End If
Timer1.Start()
Timer1.Enabled = False
Else
MessageBox.Show("Please select a file.")
End If
End Sub