-
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
-
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
-
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
-
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.