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

Re: How to Read From a Carriage Return File. by Mythran

Mythran
Mon Sep 13 10:41:42 CDT 2004

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
>
>
>



Re: How to Read From a Carriage Return File. by Santosh

Santosh
Mon Sep 13 11:18:34 CDT 2004

Thanks,

For some reason the DisplayFile only Returns ghi, 1
I want everything. from that file, line by line.
What could be wrong?

--

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
>>
>>
>>
>
>



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
> >>
> >>
> >>
> >
> >
>
>



Re: How to Read From a Carriage Return File. by Jamie

Jamie
Wed Sep 15 08:59:40 CDT 2004

Hi,

Not quite sure if this is what you need but you can use

fso.readline

to read in line by line, stick it in a loop and that would work........

"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
>
>
>



Re: How to Read From a Carriage Return File. by Mythran

Mythran
Wed Sep 15 10:48:21 CDT 2004

Hope this helps some more :)



Option Explicit

DisplayFile "C:\readme.txt"

Sub DisplayFile(ByVal Path)
Dim fso
Dim stream
Dim ch
Dim line
Dim text

Set fso = CreateObject("Scripting.FileSystemObject")
Set stream = fso.OpenTextFile(Path, 1, False)

Do Until stream.AtEndOfStream
ch = stream.Read(1)

If ch = vbCr Then
MsgBox "Current Line: " & line
' Do something with the line.
text = text & line & vbCrLf ' Append line and carriage-return and
line-feed.
line = ""
ElseIf ch = vbLf Then
MsgBox "Line Feed Found, ignoring."
Else
line = line & ch
End If
Loop

If line <> "" Then
text = text & line
End If

MsgBox "File Text: " & vbCrLf & text
stream.Close
Set stream = Nothing
Set fso = Nothing
End Sub



"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
>