# Input, Input$
{: .no_toc }

Returns a fixed number of characters read from a file opened in **Input** or **Binary** mode.

Syntax:
- **Input(** *Number* **,** [ **#** ] *FileNumber* **)** --- returns a **Variant**.
- **Input$(** *Number* **,** [ **#** ] *FileNumber* **)** --- returns a **String**.

*Number*
: *required* The number of characters to return.

*FileNumber*
: *required* The file number used to open the file with the [**Open**](/tB/Core/Open.md) statement.

Data read with **Input** is usually written to a file with **Print #** or **[Put](/tB/Core/Put.md)**. Use this function only with files opened in **Input** or **Binary** mode.

Unlike the **Input #** statement, the **Input** function returns all the characters it reads, including commas, carriage returns, linefeeds, quotation marks, and leading spaces.

For files opened for **Binary** access, an attempt to read through the file using **Input** until [**EOF**](/tB/Modules/FileSystem/EOF.md) returns **True** generates an error. Use [**LOF**](/tB/Modules/FileSystem/LOF.md) and [**Loc**](/tB/Modules/FileSystem/Loc.md) instead of **EOF** when reading binary files with **Input**, or use **[Get](/tB/Core/Get.md)** when **EOF** is needed.

> [!NOTE]
> Use [**InputB**](/tB/Modules/FileSystem/InputB.md) for byte data contained within text files. With **InputB**, *Number* specifies the number of bytes to return rather than the number of characters.

### Common Errors

| Error | When |
|---|---|
| [-2147467259 (`&H80004005`)](/Reference/Run-time-Errors.md#-2147467259), *Unspecified error* | *Number* is more characters than are left in a file open for **Input**<br>the file is open for **Output**, **Append** or **Random**<br>*Number* is negative, after rounding<br>*FileNumber* is not the number of an open file<br>*Number* is 0, after rounding |
| [94 (`&H5E`)](/Reference/Run-time-Errors.md#94), *Invalid use of Null* | *Number* or *FileNumber* is **Null** |

> [!NOTE] BETA 1045
> When *Number* is more characters than are left in a file open for **Input**, VB6 and 64-bit VBA raise error [62 (`&H3E`)](/Reference/Run-time-Errors.md#62), *Input past end of file*, instead.

> [!NOTE] BETA 1045
> When the file is open for **Output**, **Append** or **Random**, VB6 and 64-bit VBA raise error [54 (`&H36`)](/Reference/Run-time-Errors.md#54), *Bad file mode*, instead.

> [!NOTE] BETA 1045
> When *Number* is negative, after rounding, VB6 and 64-bit VBA raise error [5 (`&H5`)](/Reference/Run-time-Errors.md#5), *Invalid procedure call or argument*, instead.

> [!NOTE] BETA 1045
> When *FileNumber* is not the number of an open file, VB6 and 64-bit VBA raise error [52 (`&H34`)](/Reference/Run-time-Errors.md#52), *Bad file name or number*, instead.

> [!NOTE] BETA 1045
> When *Number* is 0, after rounding, VB6 and 64-bit VBA raise no error.

### Example

This example uses the **Input** function to read one character at a time from a file and print it to the [Debug Console](/tB/IDE/Debugging/Debug-Console.md). *TESTFILE* is assumed to be a text file with a few lines of sample data.

```tb check_build
Dim MyChar As Variant
Open "TESTFILE" For Input As #1     ' Open file.
Do While Not EOF(1)                 ' Loop until end of file.
    MyChar = Input(1, #1)           ' Get one character.
    Debug.Print MyChar              ' Print to the Debug Console.
Loop
Close #1                            ' Close file.
```

### See Also

- [InputB, InputB$](/tB/Modules/FileSystem/InputB.md) functions
- [Open](/tB/Core/Open.md) statement
- [EOF](/tB/Modules/FileSystem/EOF.md), [LOF](/tB/Modules/FileSystem/LOF.md), [Loc](/tB/Modules/FileSystem/Loc.md) functions
