InputString Function


InputString Function

Class

Microsoft.VisualBasic.FileSystem

Syntax

     Dim result As String = InputString(fileNumber, charCount) 


fileNumber (required; Integer)

Any valid file number of a file opened with FileOpen


charCount (required; Integer)

Number of characters to read from the file

Description

The InputString function reads data from a file into a string variable, up to charCount characters in length.

Usage at a Glance

  • InputString should only be used with files opened in Input or Binary modes.

  • InputString begins reading from the current read position in the file.

  • InputString returns all the characters it reads, regardless of their type. This includes spaces, carriage returns, line feeds, commas, end-of-file markers, unprintable characters, and so on.

  • Once the function finishes reading charCount characters, it advances the current file position charCount characters.

  • InputString is often used with data written to a file using the Print, PrintLine, or FilePut procedures.

  • If a read of charCount characters moves past the end of the file, an error occurs.

Example

If the file c:\data.txt contains the data:

     abcdefghijklmnopq 

the following code reads the characters, three at a time:

     Dim oneLine As String     Dim counter As Long     Dim fileID As Integer = FreeFile(  )     FileOpen(fileID, "c:\data2.txt", OpenMode.Input)     For counter = 1 To LOF(fileID) \ 3        oneLine = InputString(fileID, 3)        Console.WriteLine(oneLine)     Next counter     FileClose(fileID) 

Version Differences

  • The new InputString function corresponds to the VB 6 Input, Input$, InputB, and InputB$ functions.

  • The order of parameters is reversed between the VB 6 and .NET versions. In VB 6, the first parameter is charCount and the second is fileNumber.

  • In Visual Basic 2005, the My.Computer.FileSystem object provides more robust access to file management features.

See Also

FilePut, FilePutObject Procedures, Print, PrintLine Procedures




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net