Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Input Function

Input Function

Reads data from an open sequential file and assigns the data to variables.

Public Sub Input( _
   FileNumber As Integer, _
   ByRef Value As Object _
)

Parameters

FileNumber
Required. Any valid file number.
Value
Required. Variable that is assigned the values read from the file — can't be an array or object variable.

Exceptions/Errors

Exception type Error number Condition
IOException 52 FileNumber does not exist.
IOException 54 File mode is invalid.

Remarks

Data read with Input is usually written to a file with Write. Use this function only with files opened in Input or Binary mode.

Security Note   When reading from files, do not make decisions about the contents of the file based on the file name extension. For example, a file named Form1.vb may not be a Visual Basic .NET source file.

When read, standard string or numeric data is assigned to variables without modification. The following table illustrates how other input data are treated:

Data Value assigned to variable
Delimiting comma or blank line Empty
#NULL# DBNull
#TRUE# or #FALSE# True or False
#yyyy-mm-dd hh:mm:ss# The date and/or time represented by the expression
#ERROR errornumber# errornumber (variable is an object tagged as an error)

If you reach the end of the file while you are inputting a data item, the input is terminated and an error occurs.

Note   The Input function is not localized. For example, in the German version, if you input 3,14159, it will return only 3, since the comma is treated as a variable separator, rather than a decimal point.

Security Note   Reading from a file with the Input function requires Read access from the FileIOPermissionAccess enumeration. For more information, see FileIOPermissionAccess Enumeration.

Example

This example uses the Input function to read data from a file into two variables. This example assumes that TESTFILE is a file with a few lines of data written to it using the Write function; that is, each line contains a string in quotations and a number separated by a comma, for example, ("Hello", 234).

FileOpen(1, "TESTFILE", OpenMode.Output)
Write(1, "hello")
Write(1, 14)
FileClose(1)

Dim s As String
Dim i As Integer
FileOpen(1, "TESTFILE", OpenMode.Input)
Input(1, s)
Debug.WriteLine(s)
Input(1, i)
Debug.WriteLine(i)
FileClose(1)

Smart Device Developer Notes

This function is not supported.

Requirements

Namespace: Microsoft.VisualBasic

Module: FileSystem

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)

See Also

InputString Function | FileOpen Function | Print, PrintLine Functions | Write, WriteLine Functions | File Access with Visual Basic Run-Time Functions| IOException Class

Show:
© 2015 Microsoft