darude
asked on
Writing text files
Hi,
I have a list box containing data. I need to get the program to write a text file containing the data possibly with the ability to re load it at a later date too.
can you help?
Cheers
Darude :)
I have a list box containing data. I need to get the program to write a text file containing the data possibly with the ability to re load it at a later date too.
can you help?
Cheers
Darude :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Call export(List1, "a:\temp.txt")
End Sub
Private Sub Command2_Click()
List1.Clear 'OMIT THIS TO ADD TE CONTENTS TO AN EXISTING LIST.
Call import(List1, "a:\temp.txt")
End Sub
Private Function export(list As Object, sfile As String)
Dim n As Integer, c As Long
n = FreeFile
Open sfile For Output As n
For c = 0 To list.ListCount - 1
Print #n, list.list(c)
Next
Close n
End Function
Private Function import(list As Object, sfile As String)
Dim n As Integer, sLine As String
n = FreeFile
Open sfile For Input As n
While Not (EOF(n))
Line Input #n, sLine
list.AddItem sLine
Wend
Close n
End Function