InputB, InputB$

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 statement.

InputB is the byte-oriented counterpart of Input. 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), Unspecified error Number is more bytes than are left in a file open for Input
the file is open for Output, Append or Random
Number is negative, after rounding
FileNumber is not the number of an open file
94 (&H5E), Invalid use of Null Number or FileNumber is Null

Note BETA 1034

When Number is more bytes than are left in a file open for Input, VB6 and 64-bit VBA raise error 62 (&H3E), Input past end of file, instead.

Note BETA 1034

When the file is open for Output, Append or Random, VB6 and 64-bit VBA raise error 54 (&H36), Bad file mode, instead.

Note BETA 1034

When Number is negative, after rounding, VB6 and 64-bit VBA raise error 5 (&H5), Invalid procedure call or argument, instead.

Note BETA 1034

When FileNumber is not the number of an open file, VB6 and 64-bit VBA raise error 52 (&H34), Bad file name or number, instead.

Example

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