Input Procedure |
Microsoft.VisualBasic.FileSystem
Input( filenumber,value )
Any valid file number
Data to read from file
Reads delimited data from a file into variables . This statement is used to read files that were created using the Write procedure, in which case the items are comma delimited with quotation marks around strings.
Data read by Input has usually been written using the Write procedure.
Use this statement with files that have been opened in Input or Binary mode only.
If value is numeric and the Input procedure encounters non-numeric data, an InvalidCastException exception occurs.
The Input procedure strips off the quotation marks that it finds around strings.
After the Input procedure reads value , it advances the file pointer to the next unread variable or, if the file contains no additional delimited data, to the end of the file.
If the end of the file is reached during the operation of the Input procedure, an error is generated.
The Input procedure assigns string or numeric data to value without modification. However, other types of data can be modified as shown in the following table:
Data | Value assigned to variable |
---|---|
Delimiting comma or blank line | "" (empty string) |
#TRUE# or #FALSE# | True or False |
#yyyy-mm-dd hh:mm:ss# | Date and/or time |
Note that #TRUE# and #FALSE# are case sensitive.
If the file c:\data.txt contains the following data:
"one", "two", "three"
then the following code will print each string on a separate line in the Output window:
Dim fr As Integer = FreeFile( ) Dim sLine As String FileOpen(fr, "c:\data.txt", OpenMode.Input) Do While Not EOF(fr) Input(fr, sLine) Console.WriteLine(sLine) Loop FileClose(fr)
Use the EOF function to determine whether the end of the file has been reached.
Use the Write procedure to write data to a file, since Write delimits data fields correctly. This ensures that the data can be read correctly with the Input procedure.
The VB.NET Input procedure corresponds to the VB 6 Input procedure, with a number of significant differences:
The # symbol, which optionally preceded filenumber in VB 6, is not supported in VB.NET.
In VB 6, the value argument could be a comma-delimited list of variables. In VB.NET, it must be a single variable of any type.
In VB 6, if value is numeric and the data read from the file is not numeric, value is initialized to the default value for that type. In VB.NET, this generates an exception.
In addition to the standard data types, VB 6 also recognizes Empty, Null, and Error types. In VB.NET, these are not supported.
Write Procedure