Input # statement reads data from a Sequential file and assigns that data to variables. Input function returns characters from a file opened in Input or Binary mode.
The Input # statement has two parameters FileNum and VarList. The required FileNum argument is the associated file number used in the Open statement when the file was opened. The required VarList argument is a comma delimited list of variables that are assigned values read from the file.
The Input function has two parameters: Num and FileNum. The required Num argument is a number or valid numeric expression specifying the number of characters (bytes) to be read from the file. FileNum is the associated file number used in the Open statement when the file was opened.
The file system tracks all open files and the current position of access within every file. Every statement or function that accesses the data within a file, alters the current position within that file. The Loc function can be used to determine the current position within an open file.
Use the LOF and Loc functions instead of EOF when reading binary files with the Input function, or use Get when using the EOF function.
An error occurs with files opened for Binary access, when the file is read using the Input function until EOF returns True.
Data read with the Input # statement has usually been written to a file with the Write # statement. Data read with the Input function has usually been written to a file with the Print # or Put statements.
When saving data to a file for future reading with the Input # statement, use the Write # statement instead of the Print # statement to write the data to the file. Using Write # properly delimits each separate data field, so it can be read back in using Input #. Using Write # also formats the data in a manner that will allow correct read operations in most locales.
Input #(FileNum, VarList)
An Integer or numeric expression representing any valid number in the range 1 to 511 inclusive, which is referenced by the file system to be associated with an open file.
A predefined valid CitectVBA variable name or comma delimited list of valid variable names.
Input # statement returns data record by record from a file opened in Input or Binary mode. Data items in a file must appear in the same order as the variables in VarList and match variables of the same data type. If a variable is numeric and the data is not numeric, a value of zero is assigned to the variable.
Input function returns a String containing characters from a file opened in Input or Binary mode. The Input function returns all of the characters it reads, including commas, carriage returns, linefeeds, quotation marks, and leading spaces.
Get # | GetAttr | Line Input # | Print # | Put # | Write #
Dim strFileContents As String
Dim strTemp As String
Dim strString As String
Dim intFileNum as Integer
Dim intNumber as Integer
intFileNum = FreeFile 'retrieve next free file number
Open "c:\test.txt" For Input As #intFileNum ' open file.
Do While Not EOF(intFileNum) ' loop until end of file
strTemp = Input(10, #intFileNum) ' read next ten characters
strFileContents = strFileContents & strTemp ' join strings
Input #intFileNum, strString, intNumber ' Read data into two variables.