TestStream ReadLine

Posted on 2009-02-08
Last Modified: 2013-11-25

In performing a ReadLine method, the statement is inserting extraneous bytes into the string.  See attached file and code.

I know from stepping through the code that the problem is in the ReadLine statements, not the Writelines, which are working correctly.

By the way, I know that there are better ways to copy a file - the object is to test the Readline - not to do the actual copying.

Thanks for your help
Dim oFSO As New Scripting.FileSystemObject

        Dim oTS As Scripting.TextStream

        Dim oTS2 As Scripting.TextStream



        Dim strRetp As String



        Set oTS = oFSO.OpenTextFile(ReportDir & "\myfile.txt")

        Set oTS2 = oFSO.CreateTextFile(ReportDir & "\myfile2.txt", ForWriting, True)


        strRetp = oTS.ReadLine

        oTS2.WriteLine strRetp


        strRetp = oTS.ReadLine

        oTS2.WriteLine strRetp


        strRetp = oTS.ReadLine

        oTS2.WriteLine strRetp


        strRetp = oTS.ReadAll

        oTS2.WriteLine strRetp




        Set oTS = Nothing

        Set oTS2 = Nothing

Open in new window

Question by:simb11
    1 Comment

    Accepted Solution

    I figured out the answer.  Instead of CreateTextFile, I used OpenTextFile.  The problems were resolved.  Not sure why it made a difference to the Readline, but it works.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now