Reads data from a previously opened file.
Input #n,v1[,v2,...]
Line Input #n,s1[,s2...]
$ = Input$(count, #n) $ = Input?(count, #n)
n: integer expression; channel number count: number of characters #n : channel number s1, s2,...: strings v1,v2,...: any variable type
All these commands read data from a file, accessed with the channel number n (from 0 to 511).
For Line Input and Input, either individual values or whole variable lists can be read, the latter being separated by commas; Line Input is optimised to accept string variables and does not read a mid-line comma as a data separator; Input is also capable of reading strings (and sometimes does it better), as well as being suited to reading numeric values; both are restricted to inputting ±1,000 character strings and both internally use TextEOF to test for an end-of-file situation.
The Input$() and Input?() are synonymous and read the specified number of characters from #n into a string variable which is automatically expanded or contracted to fit. Unlike the Input and Line Input commands, these functions are only limited to the legal size of a string (roughly 228 characters long); however, also unlike the two commands, when reading the full length of a string written by a Print # statement, these functions do not then remove the record separator at the end of the string and so, to read the next record, the separator needs to be cleared by using a dummy Input# call. The only difference between these two functions is that INput? prevents an error being raised if the number of characters in the string being imported is larger than the number of bytes left in the file.
Local a$, b$, c$, d$, e$, f$, g$, n%, txt$ = "'Hello, how are you?', 'I am fine, thanks'"#13#10"'That's good to hear.'"
Open App.Path & "\temp.dat" for Output As # 1
Write # 1, txt$
Print # 1, txt$
Print # 1; Len(txt$) : Print # 1, txt$
Close # 1
Open App.Path & "\temp.dat" for Input As # 1
Line Input # 1;a$ // a$ reads the first iteration of txt$
Line Input # 1;b$, c$ // but both b$ and c$ are required to read the second due to the commas
Close # 1
Print "Line Input:" : Print "a$ = "; a$ : Print "b$ = "; b$ : Print "c$ = "; c$ : Print
Open App.Path & "\temp.dat" for Input As # 1
Input # 1;a$ // a$ reads the first iteration of txt$
Input # 1;b$, c$, d$, e$, f$ // but b$, c$, d$, e$ and f$ are required to read the second due to the commas
Input # 1;n% : g$ = Input$(n, # 1)
Print "Input:" : Print "a$ = "; a$ : Print "b$ = "; b$ : Print "c$ = "; c$
Print "d$ = "; d$ : Print "e$ = "; e$ : Print "f$ = "; f$ : Print
Print "Input$:" : Print "g$ = "; g$
Print "EOF? = "; EOF(# 1) // There is still the record separator remaining at the end of the file
Input # 1;a$
Print "EOF? = "; EOF(# 1) // Now the end of the file is reached
Close # 1
Kill App.Path & "\temp.dat"
None of these functions and commands were implemented to work with a "COM:" port or any other interface, but are built to work only with files and are optimized in that direction. If you want to read in through a different interface, please use the ReadFile() Windows API Function instead.
However, Input and Line Input (without the file number) are able to receive input from the keyboard (see here).
Finally, to deal with large string arrays, it is sometimes better to use
{Created by Sjouke Hamstra; Last updated: 15/02/2023 by James Gaite}