VBScript » Objects » TextStream

Version: 2.0

The TextStream object provides sequential access to the contents of any file where the contents are in text-readable form. You can create an instance of the TextStream object using the CreateTextFile or OpenTextFile methods of the FileSystemObject object, or alternatively by using the OpenAsTextStream method of the File object.

Examples

Code:
<%
Dim filesys, testfile
Set filesys = CreateObject("Scripting.FileSystemObject")
Set testfile= filesys.CreateTextFile("c:\somefile.txt", True)
testfile.WriteLine "Your text goes here."
testfile.Close
%>
Explanation:

In this code the CreateTextFile method is used on the FileSystemObject to return the TextStream object, "testfile". This TextStream object is then manipulated using the WriteLine and Close methods.

Properties

AtEndOfLine

Syntax: object.AtEndOfLine

Returns a Boolean value. If the file pointer is positioned immediately before the file's end-of-line marker, the value is True, and False otherwise.

AtEndOfStream

Syntax: object.AtEndOfStream

Returns a Boolean value. If the file pointer is positioned at the end of a file, the value is True, and False otherwise.

Column

Syntax: object.Column

Returns the current position of the file pointer within the current line. Column 1 is the first character in each line.

Line

Syntax: object.Line

This property returns the current line number in a text file.

Methods

Close

Syntax: object.Close

Closes a currently open TextStream file.

Read

Syntax: object.Read(characters)

This method reads the number of characters you specify from a Textstream file and returns them as a string.

ReadAll

Syntax: object.ReadAll

This method reads the entire contents of a text file and returns it as a string.

ReadLine

Syntax: object.ReadLine

Reads a single line (excluding the newline character) from a TextStream file and returns the contents as a string.

Skip

Syntax: object.Skip(numberofcharacters)

Causes the file pointer to skip ahead a specified number of characters when reading a TextStream file.

SkipLine

Syntax: object.SkipLine

Moves the file pointer from its current position to the beginning of the next line.

Write

Syntax: object.Write(string)

This method writes a supplied string to an open TextStream file.

WriteBlankLines

Syntax: object.WriteBlankLines(lines)

Used to write a number of consecutive newline characters (defined with the lines parameter) to a TextStream file.

WriteLine

Syntax: object.WriteLine([string])

Writes a supplied string to a TextStream file, followed by a new line character.

Events

Initialize

See Also: