Results 1 to 2 of 2

Thread: loading and saving a list into a listbox

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2000
    Location
    Launceston, Tasmania, Australia
    Posts
    44

    Post

    ok so how do you save a listboxes list as a text file because the following code I usually use does not work:

    open "C:\List.txt" for output as #1
    Print #1, Listbox1.list
    close #1

    I get an invalid argument.

    and if i try it like this

    open "C:\List.txt" for output as #1
    Print #1, Listbox1.text
    close #1

    it just save a blank text file.

    also how do you then import a text file into a list box?

    thanx


    ------------------
    Mooose

  2. #2
    Lively Member
    Join Date
    Jan 2000
    Location
    Springfield, IL
    Posts
    124

    Post

    I am not sure how you move the entire list at one time, but this code will loop through the list and save one item at a time. It will also load the data into the listbox.
    Code:
    Private Sub cmdLoad_Click()
        Dim strInputData As String
        
        Listbox1.clear
        Open "C:\List.txt" For Input As #1
        Do While Not EOF(1)   ' Check for end of file.
            Line Input #1, strInputData   ' Read line of data.
            Listbox1.AddItem Trim(strInputData)
        Loop
        Close #1
    
    End Sub
    
    Private Sub cmdSave_Click()
        
        Dim i As Integer
        
        Open "C:\List.txt" For Output As #1
        For i = 0 To Listbox1.ListCount - 1
            Print #1, Listbox1.List(i)
        Next i
        Close #1
    
    End Sub

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