• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1678
  • 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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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