i am writing a file using data from a list box, I have a bunch of names in a listbox that i want to save to a file. how do i do this. i am outputing to a text file(.txt)
do i use the write function?? if yes or not how do i do it??
Printable View
i am writing a file using data from a list box, I have a bunch of names in a listbox that i want to save to a file. how do i do this. i am outputing to a text file(.txt)
do i use the write function?? if yes or not how do i do it??
To save the listbox:
To load:Code:Public Sub List_Save(TheList As ListBox, FileName As String)
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
Code:Public Sub List_Load(TheList As ListBox, FileName As String)
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
private function WriteListToFile
Dim i As Integer
'first create a textbox to contain all the names
'by the way...there are many other ways how to do this function
For i = 0 To List1.ListCount
Text1.Text = Text1.Text & List1.List(i) & vbCrLf
Next i
open "c:\NewFile.txt" for output as #1
print #1,text1.text
close #1
'walla!!