CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2000
    Location
    Arizona, USA
    Posts
    493

    Read All Data From A Text File

    Is there an easy way to read all the data in a text file into a string, without looping and
    reading each line to build the string? I thought you could do it with the FileSystemObject but
    I can't seem to find how.
    Thanks for any help.

    Kris
    Software Engineer
    Phoenix,AZ
    Kris
    Software Engineer
    Phoenix, AZ USA

  2. #2
    Join Date
    Aug 2000
    Location
    KY
    Posts
    766

    Re: Read All Data From A Text File

    you can use a stream object and issue a ReadText. The stream object is available is you are using ADO 2.6


    dim str as string
    Dim ts as Stream
    set ts = new Stream
    ts.LoadFromFile {filename}
    str = ts.readtext
    set ts = nothing






  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Read All Data From A Text File

    The following sample will read a text file into a variable called Text1.text

    ' Read a file into a TEXT box using binary read
    ' this reduces the exposure of VB editing double quote marks and
    ' commas out of the text

    private Sub Command1_Click()
    Dim a
    a = "C:\to DO LIST\1.txt"
    Open a for binary as #1
    Text1.Text = input(FileLen(a), #1)
    Close

    End Sub




    John G

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured