# InputB, InputB$
{: .no_toc }

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

Syntax:
- **InputB(** *Number* **,** [ **#** ] *FileNumber* **)** --- returns a **Variant**.
- **InputB$(** *Number* **,** [ **#** ] *FileNumber* **)** --- returns a **String** whose underlying bytes are the bytes that were read.

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

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

**InputB** is the byte-oriented counterpart of [**Input**](/tB/Modules/FileSystem/Input.md). Where **Input** counts and returns characters (two bytes per character in twinBASIC's UTF-16 buffer), **InputB** counts and returns raw bytes --- useful when reading binary data through a textually-opened channel.

The bytes are packed into the result without any character-set translation; the **String** form simply reinterprets the byte run as a UTF-16 string for storage.

### Common Errors

| Error | When |
|---|---|
| [-2147467259 (`&H80004005`)](/Reference/Run-time-Errors.md#-2147467259), *Unspecified error* | *Number* is more bytes 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 |
| [94 (`&H5E`)](/Reference/Run-time-Errors.md#94), *Invalid use of Null* | *Number* or *FileNumber* is **Null** |

> [!NOTE] BETA 1045
> When *Number* is more bytes 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.

### Example

```tb check_build
Dim Bytes As Variant
Open "data.bin" For Binary Access Read As #1
Bytes = InputB(LOF(1), 1)            ' Read the whole file as bytes.
Close #1
```

### See Also

- [Input, Input$](/tB/Modules/FileSystem/Input.md) functions
- [Open](/tB/Core/Open.md) statement
- [LOF](/tB/Modules/FileSystem/LOF.md) function
