INPUT - Statement

INPUT([#] filenumber, varlist)

Reads data from a file and assigns the data to a list of variables (Long).


filenumberThe number of the file (Integer).
varlistThe variable name to read the input to.

REMARKS
* For an example refer to the page under Reading Text Files
* All of the characters, including commas, carriage returns, line feeds, quotation marks and leading spaces are included.
* The "varlist" should contain one or more comma delimited variables.
* Data read using this statement is usually written to using the Write statement.
* Using the Write statement ensures each separate data field is properly delimited.
* If you reach the end of the file the input is terminated and an error occurs.
* Data items in a file must appear in the same order as the variables and also match their data types.
* If a variable is numeric but the data is not then a zero value is assigned.
* Your file should not contain any strings that include embedded quotation marks.
* Any strings that contain embedded quotation marks will be treated as separate strings.
* This statement is not available in Access.
* You can use the CLOSE statement to close a text file.
* You can use the EOF function to return the value indicating if the end of a file has been reached.
* You can use the INPUT Function to read a number of characters from a file.
* You can use the LINE INPUT statement to read a single line from a file opened with Sequential access.
* You can use the OPEN statement to open a text file.
* You can use the PRINT statement to write data to a file opened with Sequential access (display-formatted).
* You can use the WRITE statement to write data to a file opened with Sequential access.
* For the Microsoft documentation refer to learn.microsoft.com

Open "C:\Temp\MyText.txt" For Output As #1 
Print #1, "one,two,three"
Write #1, "four,five,six"
Close #1

Open "C:\Temp\MyText.txt" For Input As #1

Do Until VBA.EOF(1)
    Dim LineFromFile As String
    Line Input #1, LineFromFile

    Dim VarName1, VarName2 As Variant
    Input #1, VarName1, VarName2

    Debug.Print LineFromFile
    Debug.Print VarName1, VarName2
Loop
Close #1

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top