Click to See Complete Forum and Search --> : Read All Data From A Text File
softweng
June 28th, 2001, 01:10 PM
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
dfwade
June 28th, 2001, 01:37 PM
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
John G Duffy
June 28th, 2001, 04:43 PM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.