Results 1 to 4 of 4

Thread: [RESOLVED]Saving the contents of a Listbox to a txt

  1. #1

    Thread Starter
    Addicted Member Garrett19212's Avatar
    Join Date
    Jan 2005
    Location
    US
    Posts
    220

    Resolved [RESOLVED]Saving the contents of a Listbox to a txt

    How can I save the contents of a listbox to a txt file?

    Meaning by each line of a listbox is a line in the txt file.
    Last edited by Garrett19212; Aug 26th, 2005 at 10:41 PM.

  2. #2
    Junior Member
    Join Date
    Aug 2005
    Posts
    18

    Post Re: Saving the contents of a Listbox to a txt

    You can do it like this:

    VB Code:
    1. Open FileName for Output as #1 'Opens the file to write
    2.    For i = 0 to List1.Listcount -1  
    3.       Line = List1.List(i)   ' Reads the list-item
    4.       Print #1, Line & vbCrLf ' Writes it in the file
    5.    Next i
    6. Close #1   ' Closes the file

    Hope it helps

  3. #3
    Fanatic Member
    Join Date
    Mar 2005
    Posts
    546

    Re: Saving the contents of a Listbox to a txt

    Here's one way:

    VB Code:
    1. Open "c:\path\filename.txt" for output as #1
    2. For x = 0 to list1.listcount - 1
    3. print #1, list1.list(x)
    4. next
    5. Close #1

    By the way, I found this by a search through the forums

    Thread I found it in:

    http://vbforums.com/showthread.php?t...s+listbox+file
    Did you find a post in this thread useful? Please click Rate This Post.

  4. #4

    Thread Starter
    Addicted Member Garrett19212's Avatar
    Join Date
    Jan 2005
    Location
    US
    Posts
    220

    Re: Saving the contents of a Listbox to a txt

    Thank you both works great, I use search just can never find what I want, I suck with keywords.

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