Solved

VB6 - Save List1 to Text file issue

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

911 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