Results 1 to 2 of 2

Thread: Saving ListBox information to a file.?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    12

    Saving ListBox information to a file.?

    Hi, I'm trying to save information inside of a ListBox to a *.txt file.
    This is the code im using:

    Private Sub cmdSave_Click()
    Dim FileName As String
    dlgFile.Action = 2
    FileName = dlgFile.FileName
    F = FreeFile
    Open FileName For Output As #F
    Print #F, lstPolicy.text
    Close #F
    End Sub

    I can get information in a textbox and label to save to a file but i cant seem to get the right ListBox property to save the lstpolicy information to a file. Can anyone help me?

    -Flaw

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    If you want to save all the information in a listbox you can use code simular to this:
    VB Code:
    1. Dim n As Long
    2. Dim nCount As Long
    3. Dim sFileName As String
    4. Dim hFile As Integer
    5.  
    6. dlg.ShowSave 'use this instead of the Action property which is depricated
    7. sFileName = dlg.FileName
    8. nCount = List1.ListCount - 1
    9. hFile = FreeFile
    10. Open sFileName For Output As #hFile
    11. For n = 0 To nCount
    12.     Print #hFile, List1.List(n)
    13. Next
    14. Close #hFile
    Best regards

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