Results 1 to 9 of 9
  1. #1
    muteninja's Avatar
    Join Date
    Jul 2012
    Gender
    male
    Posts
    163
    Reputation
    16
    Thanks
    5
    My Mood
    Confused

    Exclamation Create New Text File from List Box

    Anyone know the code for creating a new text file containing the items in a list box? i know how to write into a existing textfile but how do you create a new one? preferably including the ability to select file destination

  2. #2
    Biesi's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Posts
    4,993
    Reputation
    374
    Thanks
    8,808
    My Mood
    Twisted
    https://msdn.microsof*****m/en-us/libr...vs.110%29.aspx

    Code:
    Dim contents As New List(Of String)
    For Each itm As Object In ListBox1.Items
        contents.Add(itm.ToString())
    Next
    File.WriteAllLines("path.txt", contents.ToArray())
    Something like this maybe

  3. The Following User Says Thank You to Biesi For This Useful Post:

    muteninja (12-17-2013)

  4. #3
    Geometrical's Avatar
    Join Date
    Jul 2012
    Gender
    male
    Location
    In the middle of nowhere.
    Posts
    1,034
    Reputation
    331
    Thanks
    10,335
    My Mood
    Chatty
    You'll need to import the 'IO' namepsace.

    Code:
    Imports System . IO
    The following will show a save file dialog where you can select where to save the text file to. The save part is from the post above.

    Code:
    Using SFD As New SaveFileDialog
        If SFD.ShowDialog() = DialogResult.Ok Then
            SFD.Filter = "Text File (*.txt) | *.txt"
            Dim Contents As New List(Of String)
            For Each Item As Object In ListBox1.Items
                contents.Add(Item.ToString())
            Next
            File.WriteAllLines(SFD.FileName, Contents.ToArray())
        End If
    End Using
    Last edited by Geometrical; 12-17-2013 at 07:29 AM.

  5. The Following User Says Thank You to Geometrical For This Useful Post:

    muteninja (12-17-2013)

  6. #4
    muteninja's Avatar
    Join Date
    Jul 2012
    Gender
    male
    Posts
    163
    Reputation
    16
    Thanks
    5
    My Mood
    Confused
    Quote Originally Posted by Biesi View Post
    https://msdn.microsof*****m/en-us/libr...vs.110%29.aspx

    Code:
    Dim contents As New List(Of String)
    For Each itm As Object In ListBox1.Items
        contents.Add(itm.ToString())
    Next
    File.WriteAllLines("path.txt", contents.ToArray())
    Something like this maybe
    the link cant be opened... what was it about?

  7. #5
    muteninja's Avatar
    Join Date
    Jul 2012
    Gender
    male
    Posts
    163
    Reputation
    16
    Thanks
    5
    My Mood
    Confused
    alright i know you will hate me for this but can you please explain the code? (im a noob)

  8. #6
    muteninja's Avatar
    Join Date
    Jul 2012
    Gender
    male
    Posts
    163
    Reputation
    16
    Thanks
    5
    My Mood
    Confused
    Quote Originally Posted by Geometrical View Post
    You'll need to import the 'IO' namepsace.

    Code:
    Imports System . IO
    The following will show a save file dialog where you can select where to save the text file to. The save part is from the post above.

    Code:
    Using SFD As New SaveFileDialog
        If SFD.ShowDialog() = DialogResult.Ok Then
            SFD.Filter = "Text File (*.txt) | *.txt"
            Dim Contents As New List(Of String)
            For Each Item As Object In ListBox1.Items
                contents.Add(Item.ToString())
            Next
            File.WriteAllLines(SFD.FileName, Contents.ToArray())
        End If
    End Using
    i copied and pasted your code what does "file" mean at File.WriteAllLines(SFD.FileName, Contents.ToArray())? and whats a importsystem****?

    noob question im ashamed

  9. #7
    muteninja's Avatar
    Join Date
    Jul 2012
    Gender
    male
    Posts
    163
    Reputation
    16
    Thanks
    5
    My Mood
    Confused
    I DID IT!!!
    using this code
    ================================================== ===============================================
    Dim saveFileDialog1 As New SaveFileDialog()

    saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
    saveFileDialog1.FilterIndex = 2
    saveFileDialog1.RestoreDirectory = True

    If saveFileDialog1.ShowDialog() = DialogResult.OK Then
    Using sw As New IO.StreamWriter(saveFileDialog1.FileName, False)
    'write each row of the ListView out to a tab-delimited line in a file
    For i As Integer = 0 To Me.List.Items.Count - 1
    sw.WriteLine(List.Items.Item(i))
    Next
    End Using
    End If
    ================================================== =========================================

  10. #8
    Geometrical's Avatar
    Join Date
    Jul 2012
    Gender
    male
    Location
    In the middle of nowhere.
    Posts
    1,034
    Reputation
    331
    Thanks
    10,335
    My Mood
    Chatty
    Quote Originally Posted by muteninja View Post
    i copied and pasted your code what does "file" mean at File.WriteAllLines(SFD.FileName, Contents.ToArray())? and whats a importsystem****?

    noob question im ashamed
    IO is a namespace in System, File is a class in it that contains functions to manipulate files.

  11. The Following User Says Thank You to Geometrical For This Useful Post:

    muteninja (12-17-2013)

  12. #9
    Biesi's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Posts
    4,993
    Reputation
    374
    Thanks
    8,808
    My Mood
    Twisted
    And the link was about the IO.File class - showing and explaining all functions

Similar Threads

  1. [WTS] Selling Brand New FIREWORK GUN from Joker box 5
    By Biomech in forum All Points Bulletin Reloaded Sell Selling / Trading / Buying
    Replies: 1
    Last Post: 04-24-2013, 01:23 PM
  2. [Solved] Creating A Text File
    By Slirpa in forum Visual Basic Programming
    Replies: 8
    Last Post: 05-05-2012, 02:38 PM
  3. How to read a text file from a website
    By ppl2pass in forum Visual Basic Programming
    Replies: 3
    Last Post: 02-13-2010, 09:19 PM
  4. CANT COPY DLL FILES FROM NEW WALLHACK!
    By beroman in forum CrossFire Hacks & Cheats
    Replies: 27
    Last Post: 01-05-2010, 09:55 AM
  5. List of .rez Files where we can copy Game Files from!
    By Stephen in forum Combat Arms Mod Discussion
    Replies: 4
    Last Post: 12-04-2009, 02:46 PM