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

can any one tell me how I can use this code to select all varibles?

Status
Not open for further replies.

Shaun29

Programmer
Oct 22, 2008
53
US
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'SAW EXTRACT BUTTON

ofd3.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 = (ofd3.FileName)
' Set the specific text to search for
strTextToFind = "C"
Texttofind = "FB"
' Set this to determine whether to match with case sensitivity
boolMatchCaseSensitive = False

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
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 Saw Cut Sheet")
Else
MsgBox(strTextToFind & vbCrLf & "was not found in" & strInputFile)
End If
 
I fuger i need a loop statment any examples would be of help
 
Shaun fyi when you post long blocks of code like that, it is hard to read when you don't wrap it in a [ code] [ /code] tag.
 
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'SAW EXTRACT BUTTON

        ofd3.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 = (ofd3.FileName)
            ' Set the specific text to search for
            strTextToFind = "C"
            Texttofind = "FB"
            ' Set this to determine whether to match with case sensitivity
            boolMatchCaseSensitive = False

            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
                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 Saw Cut Sheet")
            Else
                MsgBox(strTextToFind & vbCrLf & "was not found in" & strInputFile)
            End If [code].tag
 
sorry not fimilar with code tag .

if yo can read this i am trying to figure out a way to loop through my text file to find all strTextToFind = "C"

need to find all "C"
any sugestions?
 
i need to know how to get this to read all lines?

objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
strFoundText = ""
' Read the first line if the file is not empty
While Not objInputFile.AtEndOfStream
strLine = objInputFile.Readline
 
I think you need more help than folks on a forum can give. I encourage you to seek professional help, probably in the form of programming classes.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top