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.
any help much appreciated
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)
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
If i = lsbrange.ListCount - 1 Then
MsgBox ("Export Complete")
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.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center