Reads data from an open ... file and assigns them to variables.
Input #filenumber, varlist |
The Input # statement syntax has the following parts:
Part | Description |
filenumber | Required, any valid file number. |
varlist | Comma-delimited list of variables, to which the values read from the file are to be assigned. These can't be arrays or object variables. However variables describing array elements can be used. |
Normally data read with the Input # statement is written to a file with
the help of the Write #
statement. This statement can only be applied to the files, opened in the Input
or Binary modes.
Standard strings and numeric values that have been input are assigned to variables
without any changes. The following table demonstrates how other data is processed:
Data | Value, assigned to variable |
Comma-separator or an empty string | Empty |
#NULL# | NULL |
#TRUE# or #FALSE# | True or False |
#yyyy-mm-dd hh:mm:ss# | Resulting date and/or time. |
Quotation marks (" ") inside data being read are ignored.
Data elements in the file must follow in the same order as the variables in
the varlist and have data types corresponding to the variables. If a
variable is numeric, and the data element is non-numeric, the variable is set
to null value.
If end of file is reached when reading a data element, data input stops and
an error is generated.
Note: To ensure correct input of file data into variables when using Input #, you should always use the Write # statement (rather than Print #) when writing data into files. Using this statement ensures correct placement of separators between data elements.
In this example the Input # statement is used for reading data from a file into two variables. It's assumed that the TESTFILE file exists and contains several text strings, which have been written with the Write # statement - i.e. each string contains a string in quotation marks and a number, separated by a comma, e.g. ("Hello World", 234).
Dim MyString |
See Also |
Recording Data in a File, Open Statement, Print # Statement, Write # Statement, Input Function |