Results 1 to 3 of 3

Thread: List Box Contents to TXT file.

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Location
    Kitchener, Ontario
    Posts
    1

    Cool

    Hello

    I am a beginner VB programmer and I am looking for some suggestions/help in order to dump all the contents of a list box to a txt file.

    Open "c:\RSJ_UPDATE.TXT" For Output As #1

    Dim n As Integer
    n = 0
    Dim getlistselection As String
    getlistselection = lstdefpath.Text
    lstdefpath.ListIndex = n
    Do While getlistselection > ""
    lstdefpath.ListIndex = n
    getlistselection = lstdefpath.Text
    Print #1, getlistselection
    n = n + 1
    Loop


    Close filesavedef

    The problem is that I cannot get it to LOOP through the contents, it just keeps generating a TXT file with zero size. Any help is appreciated. Thanks.

  2. #2
    Member
    Join Date
    Aug 1999
    Location
    Houston
    Posts
    48
    I think you are going thru too much code in order to print the contents of a listbox. First, get the number of items in the list, then print them:

    numitems = lstdefpath.listcount 'determines number of list items

    for j% = 1 to numitems
    print #1, lstdefpath.list(j%)
    next j%

    this should do it

    -lp

  3. #3
    Guest
    Easiest way to save or load a 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