Results 1 to 4 of 4

Thread: Save a listbox as a text file

  1. #1

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    I thought I asked this question before, but I searched the whole forum and couldn't find the post. I'll ask again and hope that someone can help me.

    How can I save a listbox as a textfile? I am saving a playlist for an MP3 player and I need to save each item in the list on it's own line in the textbox. I'm already able to load files into the textbox, I just want to save it.

    Thanks
    <removed by admin>

  2. #2
    Guest
    Code:
    Public Sub List_Load(TheList As ListBox, FileName As String)
    'Load a file to a list box
    On Error Resume Next
    Dim TheContents As String
    Dim fFile As Integer
    fFile = FreeFile
     Open FileName For Input As fFile
       Do
         Line Input #fFile, TheContents$
            TheList.Additem TheContents$
       Loop Until EOF(fFile)
     Close fFile
    End Sub
    
    
    Public Sub List_Save(TheList As Listbox, FileName As String)
    'Save a listbox as FileName
    On Error Resume Next
    Dim Save As Long
    Dim fFile As Integer
    fFile = FreeFile
    Open FileName For Output As fFile
       For Save = 0 To TheList.ListCount - 1
          Print #fFile, TheList.List(Save)
       Next Save
    Close fFile
    End Sub

  3. #3
    Member
    Join Date
    May 2000
    Location
    Canada
    Posts
    52
    private sub cmdSave_Click()
    Dim Search as Integer
    Open "YourFile" for output as #1
    for search = 0 to list1.Listcount-1
    print #1, list1.list(search)
    next search
    close #1

  4. #4

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125

    Thanks!

    Thanks for responding so fast. I uesd your code Matthew and it works really good. D.paulson, I tried your code, and it worked, but I used Matthew's because I could use the public subs with more than one button. Thanks for posting though.
    <removed by admin>

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