We help IT Professionals succeed at work.

TestStream ReadLine

Medium Priority
1,719 Views
Last Modified: 2013-11-25
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
Comment
Watch Question

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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.