Re: How to Read From a Carriage Return File. by Al
Al
Mon Sep 13 23:11:53 CDT 2004
"Santosh" <santoshNoSpam@NoSpam.net> wrote in message
news:OOcYS1amEHA.592@TK2MSFTNGP11.phx.gbl...
> Thanks,
>
> For some reason the DisplayFile only Returns ghi, 1
> I want everything. from that file, line by line.
> What could be wrong?
My guess would be that readline assumes that lines are delimited by crlf
rather than just cr. Since your file contains only cr line delimiters,
readline is executed once, and reads in the entire file. Then the msgbox
function displays the following string:
abc, 1<cr>def, 1<cr>ghi, 1<cr>
Since no lf is present, each <cr> effectively moves the pointer back to the
beginning of the output line, where the value of the previously displayed
line is overwritten by that of the new.
/Al
>
> --
>
> Santosh
>
> "Mythran" <kip_potter@hotmail.com> wrote in message
> news:Ok6$rgamEHA.3900@TK2MSFTNGP10.phx.gbl...
> > Option Explicit
> >
> > MsgBox(ReadFile("C:\readme.txt"))
> >
> > Function ReadFile(ByVal Path)
> > Dim fso
> > Dim stream
> >
> > Set fso = CreateObject("Scripting.FileSystemObject")
> > Set stream = fso.OpenTextFile(Path, 1, False)
> >
> > ReadFile = stream.ReadAll()
> >
> > stream.Close
> >
> > Set stream = Nothing
> > Set fso = Nothing
> > End Function
> >
> > OR...
> >
> > Option Explicit
> >
> > DisplayFile "C:\readme.txt"
> >
> > Sub DisplayFile(ByVal Path)
> > Dim fso
> > Dim stream
> >
> > Set fso = CreateObject("Scripting.FileSystemObject")
> > Set stream = fso.OpenTextFile(Path, 1, False)
> >
> > Do Until stream.AtEndOfStream
> > MsgBox(stream.ReadLine())
> > Loop
> >
> > stream.Close
> > Set stream = Nothing
> > Set fso = Nothing
> > End Sub
> >
> > Hope this helps :)
> >
> > Mythran
> >
> >
> > "Santosh" <santoshNoSpam@NoSpam.net> wrote in message
> > news:ue$CPcamEHA.512@TK2MSFTNGP10.phx.gbl...
> >> Hi Everybody,
> >>
> >> I have a TextFile which has data some thing like below,
> >>
> >> abc, 1
> >> def, 1
> >> ghi, 1
> >>
> >>
> >> How do read line by Line using a FileSystem Object.
> >> The above data is in a Text file and it has Carriage Returns.
> >>
> >> Any help is Appreciated.
> >>
> >> --
> >> Santosh
> >>
> >>
> >>
> >
> >
>
>