1 Attachment(s)
VB5 - Save List Values To Text File
How do i go about saving the values in a list into a text file and then the text file list also displaying in the list?
Example, I've got a list with a text box and button to add the text into the list but i want to be able to save this list into a text file and then for the list to display the text file when i reopen the form.
Re: VB5 - Save List Values To Text File
Add the following code to your existing:
Code:
Option Explicit
'populate list when form loads
Private Sub Form_Load()
Dim strLine As String
If Not Dir(App.Path & "items.txt") = "" Then
Open App.Path & "items.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, strLine
List1.AddItem strLine
Loop
Close #1
End If
End Sub
'save list - you'll have to add command button to your form and name it btnSaveList
Private Sub btnSaveList_Click()
Dim i As Integer
If List1.ListCount = 0 Then Exit Sub
Open App.Path & "items.txt" For Output As #1
For i = 0 To List1.ListCount - 1
Print #1, List1.List(i)
Next i
Close #1
End Sub
Re: VB5 - Save List Values To Text File
Thanks once again, this is a really really big help!!