Solved

VB6 - Save List1 to Text file issue

Posted on 2014-02-08
4
459 Views
Last Modified: 2014-02-09
Hi all

I would like to save my List1 content into a Text file and save it with a specific name.

The problem i have is that it save the file but the text file content stay empty even if my List1 was populated.

Would you know why based on by below code?

Thanks again for your help.


'Save text file
Dim f%, i%

 f = FreeFile
  Open "C:\Documents and Settings\All Users\Desktop\New location: " & Format(Now, "yymmddhhmmss") For Output As #f
  file_name = "New location: " & Format(Now, "yymmddhhmmss")

          
        For i = 0 To List1.ListCount - 1
        List1.Selected(i) = True
        Print #f, List1.List(List1.ListIndex)
    Next

  
  Close #f
  FreeFile f

Open in new window

0
Comment
Question by:Wilder1626
  • 2
  • 2
4 Comments
 
LVL 11

Author Comment

by:Wilder1626
ID: 39844212
I tried like this also.

I can save the List 1 but for that, i need to create the text file first on my Desktop.

But i want to generate a new file and save it in this format: "New location: " & Format(Now, "yymmddhhmmss")

'Save text file
 Dim WriteLineTextFile As String
    
    Const ForReading = 1, ForWriting = 2
    Dim fso, f
  
    
    
       Set fso = CreateObject("Scripting.filesystemobject")
   Set f = fso.opentextfile("C:\Documents and Settings\All Users\Desktop\New location.txt", ForWriting)
  
   
    For i = 0 To List1.ListCount - 1
        List1.ListIndex = i
        f.writeline (List1.Text)
        If i = List1.ListCount - 1 Then
            
        End If
    Next i


MsgBox ("Export Complete")
    

Open in new window

0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39844258
The colon (:) is not a valid character in a file or folder name so...

Dim f%, i%

 f = FreeFile
  Open "C:\Documents and Settings\All Users\Desktop\New location " & Format(Now, "yymmddhhmmss") For Output As #f
  'file_name = "New location" & Format(Now, "yymmddhhmmss")

          
        For i = 0 To List1.ListCount - 1
        List1.Selected(i) = True
        Print #f, List1.List(List1.ListIndex)
    Next

  
  Close #f

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39846198
wonderful. This is perfect

Thanks again for your help
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39846211
You're welcome.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question