Name

TextStream.Read Method

Syntax

                  oTextStreamObj
                  .Read(Characters)
oTextStreamObj

Use: Required

Data Type: TextStream object

Any property or object variable returning a readable TextStream object.

Characters

Use: Required

Data Type: Long

The number of characters you want to read from the input stream.

Return Value

A String.

Availability

R

Description

Reads a given number of characters from a file or the standard input and returns the resulting string.

Rules at a Glance

  • Files opened for writing or appending can’t be read; you must first close the file and reopen it using the ForReading constant.

  • After the read operation, the file pointer advances Characters characters, unless the end of the file is encountered.

  • If the number of characters available to be read are less than Characters, all characters will be read.

  • When reading the standard input stream from the keyboard, program execution pauses until an end-of-line or end-of-stream character is encountered. However, only the first Characters characters of the stream are read. If at least Characters characters are available in the input stream for subsequent read operations, program execution does not pause to wait for further keyboard input. The usual technique is to process keystrokes in a loop until the end-of-stream marker is encountered. For example:

    Do While Not oIn.AtEndOfStream
       sIn = oIn.Read(10)         ' Read up to 10 characters
       ' process text
    Loop

Get VBScript in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.