Input# Statement
Načíta dáta z otvoreného sekvenčného súboru.
Syntax:
Input #FileNumber As Integer; var1[, var2[, var3[,...]]]
Paremetre:
ČísloSúboru: Číslo súboru údajmi, ktoré chcete načítať. Súbor musí byť vopred otvorený príkazom Open s kľúčovým slovom INPUT.
var: A numeric or string variable that you assign the values read from the opened file to.
The Input# statement reads numeric values or strings from an open file and assigns the data to one or more variables. A numeric variable is read up to the first carriage return (Asc=13), line feed (Asc=10), space, or comma. String variables are read to up to the first carriage return (Asc=13), line feed (Asc=10), or comma.
Data and data types in the opened file must appear in the same order as the variables that are passed in the "var" parameter. If you assign non-numeric values to a numeric variable, "var" is assigned a value of "0".
Records that are separated by commas cannot be assigned to a string variable. Quotation marks (") in the file are disregarded as well. If you want to read these characters from the file, use the Line Input# statement to read pure text files (files containing only printable characters) line by line.
If the end of the file is reached while reading a data element, an error occurs and the process is aborted.
Príklad:
Sub ExampleWorkWithAFile
Dim iCount As Integer
Dim sName As String
Dim sValue As Integer
Dim sFileName As String
sFileName = "c:\data.txt"
iCount = Freefile
' Zapíše dáta ( ktoré si prečítame pomocou Input ) do súboru
Open sFileName For Output As iCount
sName = "Hamburg"
sValue = 200
Write #iCount, sName, sValue
sName = "New York"
sValue = 300
Write #iCount, sName, sValue
sName = "Miami"
sValue = 459
Write #iCount, sName, sValue
Close #iCount
iCount = Freefile
' Prečíta dátový súbor použitím Input
Open sFileName For Input As iCount
Input #iCount; sName, sValue
MsgBox sName & " " & sValue
Input #iCount; sName, sValue
MsgBox sName & " " & sValue
Input #iCount; sName, sValue
MsgBox sName & " " & sValue
Close #iCount
End Sub