Solved

Writing text files

Posted on 2000-05-11
2
119 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 50 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

820 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