?
Solved

VB6 - Save List1 to Text file issue

Posted on 2014-02-08
4
Medium Priority
?
483 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 49

Accepted Solution

by:
Martin Liss earned 2000 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 49

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

650 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