Results 1 to 4 of 4

Thread: [RESOLVED] Writing to multiple .txt files

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Resolved [RESOLVED] Writing to multiple .txt files

    Hey Guys,

    What i'm trying to do is write to individual .txt files depending if a string is found from items in a listbox.

    code:

    Code:
                For Each itm As String In listBoxMain.Items
    
                    '// PLATFORM #1
                    If (itm.Contains("string1") Or itm.Contains("string2")) Then
    
                        Using SW As New StreamWriter("save\" & "Strings12.txt", True)
    
                            SW.WriteLine("Found - " & itm)
    
                        End Using
    
                    ElseIf (itm.Contains("string3")) Then
    
                        Using SW As New StreamWriter("save\" & "Strings3.txt", True)
    
                            SW.WriteLine("Found - " & itm)
    
                        End Using
    
                    End If
    
                Next
    So far only the first .txt file is being saved, my logic must be skewed lol

    any help would be appreciated

    cheers guys

    Graham

  2. #2
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: Writing to multiple .txt files

    Hi,

    I may not have written this the same way myself, but as it stands, your code works fine so the question to ask is what is the information contained in your ListBox?

    One thing you may need to consider is that the Contains Method of the ListBox is Case sensitive so this may be the first thing that you need to compensate for.

    Hope that helps.

    Cheers,

    Ian

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Writing to multiple .txt files

    Have you debugged that code? When you get to the ElseIf line, what is the value of 'itm' and what is "string3"? Presumably no item actually contains that String. The Contains method is case-sensitive, so maybe that could be the issue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Re: Writing to multiple .txt files

    Hey Guys,

    Ohhhh , i never knew that lol that was it J the one time i put everything in lowercase it was because the string should have been Capitalized "News" and i had "news"

    thanks a lot guys

    Graham

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width