• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1687
  • Last Modified:

TestStream ReadLine

Hi,

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
        
        oTS.Close
        oTS2.Close
        Set oTS = Nothing
        Set oTS2 = Nothing

Open in new window

myfile.txt
myfile2.txt
0
simb11
Asked:
simb11
1 Solution
 
simb11Author Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now