Re: How to Read From a Carriage Return File.

From: Mythran (kip_potter_at_hotmail.com)
Date: 09/15/04


Date: Wed, 15 Sep 2004 08:48:21 -0700

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
>



Relevant Pages

  • Re: Copy File from Web Site
    ... Sub Download ... Dim oHttp ... Set Stream = CreateObject'my error ... > control to direct the user to the file, but he must then click on it to ...
    (microsoft.public.vb.general.discussion)
  • Re: List Folders using Excel
    ... Sub Start ... Dim FSO As Scripting.FileSystemObject ... Dim Rng As Range ...
    (microsoft.public.excel.programming)
  • Re: Trying to have code close an open email after it saves.
    ... Sub SaveAsOF() ... Dim myItem As Outlook.Inspector ... Dim fso ... Dim fol As String ...
    (microsoft.public.outlook.program_vba)
  • Re: Excel macro help
    ... Sub ITEM_COUNT ... Dim fso, fol ... Dim Cell As Range ...
    (microsoft.public.excel.programming)
  • Re: ListDir
    ... > Dim myFolders() As String ... > End Sub ... > ' Dim FSO As FileSystemObject ... Is>> there a way to do the same with just the names of folders in a directory? ...
    (microsoft.public.excel.programming)