INPUT# statement

Purpose

Load variables with data from a sequential file.

Syntax

INPUT #filenum&, variable_list

Remarks

filenum& is the file number, or variable containing a file number, given when the file was openedvariable_list is a comma-delimited sequence of one or more string or numeric  variables.  When the INPUT# statement reads an unquoted data item from a file, it removes leading and trailing spaces.  If spaces are significant, place quotes around the file data, either directly or by using WRITE# to save the data to disk.  Please note that data to be quoted should not contain embedded quotes.

The data in the file must match the type(s) of the variable(s) defined in the INPUT# statement.  The file data should be separated by commas with a carriage return at the end.  The WRITE# statement is ideal for creating such files.

INPUT# also supports fixed-length and ASCIIZ string variables; however, data that is longer than the string is truncated to fit into the string.  Dynamic strings receive the data without truncation.  UDT variables may not be used, although fixed-length and ASCIIZ UDT member variables are supported.

See also

LINE  INPUT#, PRINT#, WRITE#

Example

SUB MakeFile

  ' MakeFile opens a sequential file for output.

  ' Using WRITE#, it writes lines of different

  ' data types to 'the file.

  OPEN "INPUT#.DTA" FOR OUTPUT AS #1

  StringVariable$ = "I'll be back."

  IntegerVar% = 1000

  FloatingPoint! = 30000.12

  ' Write a line of text to the sequential file.

  WRITE #1, StringVariable$, IntegerVar%, FloatingPoint!

  CLOSE #1

END SUB

 

SUB ReadFile

  ' This procedure opens a sequential file for

  ' input. Using INPUT# it reads lines of

  ' different data types from the file.

  OPEN "INPUT#.DTA" FOR INPUT AS #1

  RESET StringVariable$

  RESET IntegerVar%

  RESET FloatingPoint!

  ' Read a line of text from the sequential file.

  INPUT #1, StringVariable$, IntegerVar%, FloatingPoint!

  CLOSE #1

END SUB