Export (0) Print
Expand All

FileSystem.Input Method (Int32, Int16)

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

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static void Input(
	int FileNumber,
	ref short Value
)

Parameters

FileNumber
Type: System.Int32

Required. Any valid file number.

Value
Type: System.Int16

Required. Variable that is assigned the values read from the file—cannot be an array or object variable.

ExceptionCondition
IOException

FileNumber does not exist.

IOException

File mode is invalid.

The Input function is provided for backward compatibility and may affect performance. For non-legacy applications, the My.Computer.FileSystem object provides better performance. For more information, see File Access with Visual Basic.

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

Security noteSecurity 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 that is named Form1.vb may not be a Visual Basic 2005 source file.

When read, standard string or numeric data is assigned to variables without modification. The following table illustrates how other input data is 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 stopped and an error occurs.

NoteNote

The Input function is not localized. For example, in the German version, if you input 3,14159, it returns only 3, because the comma is treated as a variable separator instead of as a decimal point.

Security noteSecurity Note

Reading from a file by using the Input function requires Read access from the FileIOPermissionAccess enumeration. For more information, see FileIOPermissionAccess.

This example uses the Input function to read data from a file into two variables. This example assumes that TestFile is a file that has several lines of data written to it using the Write function, each line containing 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 = "teststring" 
Dim i As Integer
FileOpen(1, "TESTFILE", OpenMode.Input)
Input(1, s)
MsgBox(s)
Input(1, i)
MsgBox(i)
FileClose(1)

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft