Solved

VB6 - Save List1 to Text file issue

Posted on 2014-02-08
4
445 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 45

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 45

Expert Comment

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now