O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required