FutureBasic Logo

<<    Index    >> FutureBasic

input#   statement



Syntax
input# deviceID, var1 [, var2 ...]>

Description
This statement reads text data from the open file or serial port specified by deviceID, and stores the data into the specified variables. The variables var1, var2 etc. must be numeric, container, or string variables (not record variables).

If deviceID equals zero, then input# reads data from the keyboard. input#0, var1 [, var2...] is identical to input var1 [,var2 ...].

The data in the file (or coming in through the serial port) should be formatted as text items delimited by commas and/or carriage-returns. Each item is assigned to a separate variable. Some data conversion may occur during the assignment; see the input statement for more details.

If deviceID specifies a file, then input# reads a line of text from the file, beginning at the current "file mark" position (which is usually at the beginning of the line), and ending when a carriage-return character is encountered, or the end of the file is encountered, or 255 characters have been read, whichever occurs first. The file mark is then advanced to a position just past the last character read.

input# then attempts to assign each of the comma-delimited items in the text line to one of the variables (var1, var2 etc.) in the variable list. If there are more items in the text line than variables in the list, the extra items are discarded. If there are fewer items in the text line than variables in the list, then zeros or null strings are assigned to the extra variables.
If deviceID specifies an open serial port (i.e., if its value is _modemPort or _printerPort), then input# behaves in a similar way, except that the concepts of "file mark" and "end of file" generally don't apply.

input# is the slowest method of reading data from disk. For greater speed, try using read# instead. (Note however that input# and read# generally interpret the data in the file differently.)

input# can read the data created by print#. Note, however, that if you want to create data items that are delimited by commas, you must explicitly print comma characters between them. print# does not automatically insert commas between the items it puts out.

Note
If the file mark is already at the end of file when you execute input#, FutureBasic generates an "Input past end of file" error. To prevent this situation, check the value of eof( deviceID ) before executing input#.

See also
line input#; open; read#; write; print#; eof