Results 1 to 3 of 3

Thread: VB5 - Save List Values To Text File

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

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

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    30

    Re: VB5 - Save List Values To Text File

    Thanks once again, this is a really really big help!!

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