Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Writing text files

Posted on 2000-05-11
2
Medium Priority
?
135 Views
Last Modified: 2010-05-02
Hi,

I have a list box containing data. I need to get the program to write a text file containing the data possibly with the ability to re load it at a later date too.

can you help?

Cheers

Darude :)
0
Comment
Question by:darude
2 Comments
 
LVL 1

Accepted Solution

by:
manchula earned 200 total points
ID: 2799407
   Open "C:\temp\testlist.txt" For Output As #1
    For i = 0 To List1.ListCount - 1
        Print #1, List1.List(i)
    Next
    Close #1
0
 
LVL 18

Expert Comment

by:deighton
ID: 2799437
Private Sub Command1_Click()
    Call export(List1, "a:\temp.txt")
End Sub

Private Sub Command2_Click()
List1.Clear   'OMIT THIS TO ADD TE CONTENTS TO AN EXISTING LIST.
Call import(List1, "a:\temp.txt")
End Sub


Private Function export(list As Object, sfile As String)

    Dim n As Integer, c As Long
   
    n = FreeFile
   

    Open sfile For Output As n
       
    For c = 0 To list.ListCount - 1
       
        Print #n, list.list(c)
           
    Next
       
    Close n


End Function


Private Function import(list As Object, sfile As String)

    Dim n As Integer, sLine As String
   
    n = FreeFile
   

    Open sfile For Input As n
       
    While Not (EOF(n))
   
        Line Input #n, sLine
        list.AddItem sLine
       
    Wend
       
    Close n


End Function

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…

971 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