Results 1 to 4 of 4

Thread: Reading a listbox into a file

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    37

    Wink

    Can anyone please tell me if its possible to read a whole listbox into a text file

    Thanks

  2. #2
    Lively Member
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    96
    I suppose that you could read each listitem one at a time and write them to a file...

    don't know if that is what you are looking for

    H.
    Just trying to muddle through...

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    'fill a listbox with junk
        Dim i As Integer
        For i = 1 To 10
            List1.AddItem CInt((Rnd * 1022)) + 1
        Next i
    'open a text file for output (overwrite)
        Open "C:\my documents\myfile.txt" For Output As #1
    'loop the list and print it's contents to the file
        For i = 0 To List1.ListCount - 1
          List1.ListIndex = i
          Print #1, List1.Text
        Next i
            Close i
     'reset items
        List1.ListIndex = 0
        Command1.Enabled = False
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Guest
    To load or save to file/listbox:

    Code:
    Private 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
    
    
    
    
    
    Call List_Load(List1, "C:\MyFile.txt")
    
    
    
    
    
    Private 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
    
    
    
    
    
    Call List_Save(List1, "C:\MyFile.txt")

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