Visual Basic Language Reference  

InputString Function

Returns String value containing characters from a file opened in Input or Binary mode.

InputString(_
   ByVal FileNumber As Integer, _
   ByVal CharCount As Integer _
) As String

Parameters

FileNumber
Required. Any valid file number.
CharCount
Required. Any valid numeric expression specifying the number of characters to read.

Exceptions/Errors

Exception type Error number Condition
IOException 52 FileNumber does not exist.
ArgumentException 5 CharCount < 0 or > 214.

Remarks

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

Unlike the Input function, the InputString function returns all of the characters it reads, including commas, carriage returns, linefeeds, quotation marks, and leading spaces.

With files opened for Binary access, an attempt to read through the file using the InputString function until EOF returns True generates an error. Use the LOF and Loc functions instead of EOF when reading binary files with InputString, or use FileGet when using the EOF function.

Example

This example uses the InputString function to read one character at a time from a file and print it to the Output window. This example assumes that MYFILE is a text file with a few lines of sample data.

Dim oneChar As Char
FileOpen(1,  "MYFILE.TXT", OpenMode.Input) ' Open file.
While Not EOF(1)   ' Loop until end of file.
oneChar = (InputString(1, 1))   ' Get one character.
System.Console.Out.WriteLine(oneChar)   ' Print to the output window.
End While
FileClose(1)

See Also

Input Function | IOException | ArgumentException