INPUT#

Format

INPUT# number1, number1 <-Format 1
INPUT# number1, string1 <-Format 2
INPUT# number1, string1 CRLF <-Format 3
INPUT# number1, string1 NONULL <-Format 4
INPUT# number1, string1 BYTE <-Format 5

Description

This statement will read a variable from a file identified by file number number1. It will be stored in number1/string1. If an error occurs during a read, the system variable ERROR will be set to a non-zero value. The possible errors are listed in the error messages section the of the ASIC Manual. If you read a file past its end, the contents of variable1 are undefined.

Five formats of this statement are provided to provide greater flexibility in reading files written by ASIC and non-ASIC programs. The five formats are summarized below:

Format 1 -- Read numeric data from a file previously written by ASIC.

Format 2 -- Read string data from a file previously written by ASIC.

Format 3 -- Read strings from a non-ASIC file. Assumes the strings (CRLF) will be terminated by a CR/LF (carriage return/linefeed). Note that ASIC still considers a NULL character, if encountered, as an end of string character. Also ASIC terminates the string if 80 characters are read before encountering a CR/LF pair.

Format 4 -- Read strings from a file until 80 characters or the end (NONULL) of the file is reached. Note that ASIC still considers a NULL character, if encountered, as an end of string character.

Format 5 -- Reads a single byte from a file and stores it in string1. (BYTE) If ASIC has read a NULL byte, the string will be set to NULL and its length will be 0.

Example

Example 1:

          OPEN "I",1,"TEMP.DAT"
          INPUT#1, A$
          IF ERROR=99 THEN ENDOFFILE:

     In this example, a string will be read from file "TEMP.DAT", and it will be stored in A$. The system ERROR variable is then checked to see if End of file was reached. Note, other ERRORS could also be returned by INPUT#, besides error code 99. Refer to the error messages section for more information.

     Example 2:

          OPEN "I",1,"TEMP.DAT"
          INPUT#1, A$ NONULL
          IF ERROR=99 THEN ENDOFFILE:

     In this example, ASIC will read 80 characters from the file "TEMP.DAT", or up until the next NULL character in the file, which ever comes first.

     Example 3:

          OPEN "I",1,"CONFIG.DAT"
          INPUT#1, A$ BYTE
          IF ERROR=99 THEN ENDOFFILE:

 In this example, ASIC will read a single character from the file "CONFIG.DAT", and place it in the variable A$.

     Example 4:

          OPEN "I",1,"TEST.DAT"
          INPUT#1, A
          IF ERROR=99 THEN ENDOFFILE:

In this example, ASIC will read an integer value from the file "TEST.DAT", and place it in the integer variable "A".

     Example 5:

          OPEN "I",1,"ASCII.DAT"
          OPEN "O",2,"ASCII.NEW"
          CR$=CHR$(13)
          LF$=CHR$(10)
          CRLF$=CR$+LF$
     READMORE:
          INPUT #1, A$ CRLF
          IF ERROR=96 THEN WRITE:
          IF ERROR>0 THEN ENDOFFILE:
     WRITEWITHCRLF:
          PRINT #2,A$ NONULL
          PRINT #2,CRLF$ NONULL
          GOTO READMORE:
     WRITE:
          PRINT #2, A$ NONULL
          GOTO READMORE:
     ENDOFFILE:
          CLOSE 1
          CLOSE 2

 This example copies file ASCII.DAT to file ASCII.NEW. Note: Even though ASIC can only handle 80 character strings, this example shows that by checking the ERROR variable for a value of 96, it is possible to read the file in up-to-80-character chunks and reassemble the strings in their original forms in the new file. Also note that ASIC will still treat any NULL characters in the file as an end of string character.

Comments

Note that number1 must be a constant in the range of 1-3. It identifies a file by file number which must have previously been opened by an OPEN command for modes INPUT or RANDOM.

ASIC assumes that integers will be stored in files in 2-byte binary format, which is the format ASIC writes integers. Consequently, If a file contained a string "123", but you told ASIC to read integer "X", then ASIC would read two bytes from the file and interpret "12" as two binary bytes that it would then combine and store as "X". "X" would contain the integer value 12849. Thus to read an integer correctly, you will have had to previously written it with an ASIC program.

See Also

  • OPEN
  • CLOSE
  • PRINT#
  • FILEPOS