Input, Input$, InputB, InputB$ Functions

Syntax

Input(number, [#]filenumber)

number

Use: Required

Data Type: Numeric

Specifies the number of characters to return.

filenumber

Use: Required

Data Type: Integer

Any valid file number.

Return Value

A string (in the case of Input$ and InputB$) or a variant string (if Input or InputB) containing numbercharacters.

Description

Accesses data from within a file opened in input or binary mode.

Rules at a Glance

  • Input should be used only once with files opened in input or binary mode.

  • The function begins reading characters from the current position of the file pointer.

  • Input returns all characters it reads, regardless of their type, returning the raw data of the file. This includes spaces, carriage returns, linefeeds, commas, end-of-file markers, unprintable characters, etc.

  • Once the function finishes reading number characters, it also advances the file pointer number characters.

  • The InputB and InputB$ function variants of the Input function are used to read binary data from a file. In this case, number refers to the number of bytes to read, as opposed to the number of characters.

Programming Tips and Gotchas

  • Input reads data written to a file using either the Print# or Put statements.

  • Input always attempts to read precisely number characters from the file. If there aren't number characters from the position of the file pointer to the end of the file, Input attempts to read beyond the end of the file, thereby generating runtime error 62, ...

Get VB & VBA in a Nutshell: The Language 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.