Solved

VB6 - Save List1 to Text file issue

Posted on 2014-02-08
4
464 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 47

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 47

Expert Comment

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

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

733 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