Previous | Index | Next 

[PRB] The Line property of output TextStream always returns 1

Under VB6, the Line property of the Scripting.TextStream object always returns the current line number, regardless of whether the file has been opened for input or output, as this code snippet can prove:

        Dim fso As New Scripting.FileSystemObject
        Dim ts As TextString, i As Integer
        Set ts = fso.CreateTextFile("c:\foo.txt")
        For i = 1 To 100
            ts.WriteLine(ts.Line)
        Next

After the migration, this code doesn’t work as expected, because the Line property always returns the value 1.

The only workaround for this problem is modifying the original or migrated code to keep track of the current number of lines that were output to the file.

 

Previous | Index | Next