Discussion Locked

VBScript

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I've been trying to use the READLINE method/property to read lines from a text file based on their line number. Does anyone know if READLINE accepts arguments?

Following is the syntax.

for Row = RowCount to 1 step -1
sProfile=i.ReadLine (Row)
o.WriteLine sProfile & " " & Row
fnd = instr (sProfile, SearchPro, 1)
WScript.echo "Row #: " & row & "String " & sProfile
Next

6 replies

by blaine moore

Readline does not accept arguments.

ReadLine Method
Reads an entire line (up to, but not including, the newline character) from a TextStream file and returns the resulting string.

object.ReadLine

The object argument is always the name of aTextStream object.

Remarks
The following example shows how to use the ReadLine method to read a line from a TextStream file and return the string:

Function ReadLineTextFile
Const ForReading = 1, ForWriting = 2
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)
MyFile.WriteLine "Hello world!"
MyFile.WriteLine "The quick brown fox"
MyFile.Close
Set MyFile = fso.OpenTextFile("c:\testfile.txt", ForReading)
ReadLineTextFile = MyFile.ReadLine ' Returns "Hello world!"
End Function

by geoffreyc

Unfortunately Readline doesn't accept any arguments. Read accepts an argument that specifies the number of characters that are to be read. In order to do what you want you may need to use the Skipline method to skip over lines until you reach the one you want and then read it.

This all means that you can only go in one direction through the file and must then start from the beginning again.

This discussion is closed to new replies.