
01-05-2005, 10:06 PM
|
|
|
|
Re: Getting text file into a VBA string variable
Don,
try this
Sub ReadMultiLines()
'requires a reference to the Windows Script Host Object Model
Dim FSO As FileSystemObject
Dim tsInput As TextStream
Dim strFile As String
Dim strLine As String
strFile = "D:\DspfxId.txt"
Set FSO = New FileSystemObject
Set tsInput = FSO.OpenTextFile(strFile, 1)
Do While Not tsInput.AtEndOfStream
strLine = tsInput.ReadLine
Debug.Print strLine
Loop
tsInput.Close
Set FSO = Nothing
End Sub
Robin Hammond
www.enhanceddatasystems.com
"Don Wiss" <donwiss@no_spam.com> wrote in message
news:1k4pt0hnsrcjbn9qc1suhtp5b904j3coa4@4ax.com...
> On Thu, 6 Jan 2005, Robin Hammond <rjNOrhSPAM@PLEASEnetvigator.com> wrote:
>
>>You need something like this for binary access
>>
>>Sub ReadFile()
>>Dim hFile As Long
>>Dim strFile As String
>>Dim strData As String * 4
>>
>>hFile = FreeFile
>>strFile = "C:\Something.txt"
>>Open strFile For Binary Access Read As hFile Len = 4
>>Get hFile, 1, strData
>>Close hFile
>>MsgBox strData
>>End Sub
>
> How would I expand this to read in a file of unknown length?
>
>>or you could look at ReadLine in the filesytstemobject library
>
> Okay. But this stops at the first newline character. I'd like to read
> those
> characters in also, just as the file exists on the disk.
>
> Don <donwiss at panix.com>.
|