VB6 Save ListBox to TXT File?

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: VB6 Save ListBox to TXT File?

Hybrid View

  1. #1
    Join Date
    Jan 2005

    VB6 Save ListBox to TXT File?

    Hi, i am designing a tool to ping an ip range to see what ip address are taken, the results are listed in a list box. I want to be able to export them to a txt file, however i have only been able to hardcode the txt file path name, also the txt file has to be created previously or it wont save.

    Cany anyone show/tell me how to use the common dialog control Showsave to let me select the directory and save the text file?

    Heres the code i was using atm to write to the txt file, the check box was used to filter out results that were not a sucessful ping.

    If chkFailed.Value = 1 Then
     Dim WriteLineTextFile2 As String
            Const ForReading1 = 1, ForWriting1 = 2
            Dim fso1, f1
            Set fso1 = CreateObject("Scripting.filesystemobject")
            Set f1 = fso1.opentextfile("H:\ip.txt", ForWriting1)
            For i1 = 0 To lsbrange.ListCount - 1
                lsbrange.ListIndex = i1
                Dim str As String
                For i = 1 To Len(lsbrange.Text)
                    strtmp = Mid(lsbrange.Text, i, 5)
                    If strtmp = "-   S" Then
                        str = Mid(lsbrange.Text, i + 4, 10)
                        f1.writeline (lsbrange.Text)
                        Exit For
                    End If
                Next i
            Next i1
        Dim WriteLineTextFile As String
        Const ForReading = 1, ForWriting = 2
        Dim fso, f
            Set fso = CreateObject("Scripting.filesystemobject")
        Set f = fso.opentextfile("H:\ip.txt", ForWriting)
        For i = 0 To lsbrange.ListCount - 1
            lsbrange.ListIndex = i
            f.writeline (lsbrange.Text)
            If i = lsbrange.ListCount - 1 Then
            End If
        Next i
    End If
    MsgBox ("Export Complete")
    End Sub
    any help much appreciated


  2. #2
    Join Date
    Apr 2004
    New York City
    http://www.vbexplorer.com/VBExplorer/tips/src27.asp shows you how to use the Common Dialog control to get just the directory name, not the filename.

    Note that you must add a Common Dialog control to your project, and name it "cdMain".
    If you don't see the Common Dialog control in your Toolbox, right-click the Toolbox, choose "Components", then select "Microsoft Common Dialog Control".

    Alternately, you could just use the Directory control (DirListBox) which is in the standard VB6 Toolbox.

    If you are asking how to use the Common Dialog to get a directory from the user AND get them to name the file, look up "Common Dialog Control" in the VB Help, or on MSDN: http://msdn.microsoft.com.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center