Módulo
Contido
Índice 🔎︎

# Input# Statement

Le datos dun ficheiro secuencial aberto.

## Sintaxe:

Input #NúmeroFicheiro As Integer; var1[, var2[, var3[,...]]]

## Parámetros:

FileNumber: Number of the file that contains the data that you want to read. The file must be opened with the Open statement using the key word INPUT.

var: A numeric or string variable that you assign the values read from the opened file to.

The Input# statement reads numeric values or strings from an open file and assigns the data to one or more variables. A numeric variable is read up to the first carriage return (Asc=13), line feed (Asc=10), space, or comma. String variables are read to up to the first carriage return (Asc=13), line feed (Asc=10), or comma.

Os datos e os tipos de datos do ficheiro aberto deben aparecer na mesma orde que as variábeis pasadas no parámetro «var». Se atribúe valores non numéricos a unha variábel numérica, «var» recibe un valor «0».

Records that are separated by commas cannot be assigned to a string variable. Quotation marks (") in the file are disregarded as well. If you want to read these characters from the file, use the Line Input# statement to read pure text files (files containing only printable characters) line by line.

Se se atinxe a fin do ficheiro durante a lectura dun elemento de datos, prodúcese un erro e abórtase o proceso.

## Exemplo:

    Sub ExampleWorkWithAFile

    Dim iCount As Integer

    Dim sName As String

    Dim sValue As Integer

    Dim sFileName As String

    sFileName = "c:\data.txt"

    iCount = Freefile

    ' Write data ( which we will read later with Input ) to file

    Open sFileName For Output As iCount

    sName = "Hamburg"

    sValue = 200

    Write #iCount, sName, sValue

    sName = "New York"

    sValue = 300

    Write #iCount, sName, sValue

    sName = "Miami"

    sValue = 459

    Write #iCount, sName, sValue

    Close #iCount

    iCount = Freefile

    ' Read data file using Input

    Open sFileName For Input As iCount

    Input #iCount; sName, sValue

    MsgBox sName & " " & sValue

    Input #iCount; sName, sValue

    MsgBox sName & " " & sValue

    Input #iCount; sName, sValue

    MsgBox sName & " " & sValue

    Close #iCount

    End Sub