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
* 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 return the open stream of an Input or Binary file.
* You can use the LINE INPUT statement to reads a single line from an Open sequential file and assigns it to a string.
* You can use the OPEN statement to open a text file or csv file.
* You can use the PRINT statement to write display-formatted data to a sequential file.
* You can use the WRITE statement to write data to a sequential file.
* For the Microsoft documentation refer to learn.microsoft.com

Open "C:\Temp\MyText.txt" For Output As #1 
VBA.Print #1, "one,two,three"
VBA.Write #1, "four,five,six"
VBA.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