Contido

# Instrución Put#

Escribe un rexistro nun ficheiro relativo ou unha secuencia de bytes nun ficheiro binario.

Use Print# statement to print data to a sequential text file. Use Write# statement to write data to a sequential text file with delimiting characters.

### Sintaxe:

    Put [#]fileNum, [recordNum|filePos], variable

### Parámetros:

fileNum: Any integer expression that defines the file that you want to write to.

recordNum, filePos: For relative files (random access files), the number of the record that you want to write.

En ficheiros binarios (acceso binario), a posición do byte no ficheiro onde desexa iniciar a escritura.

variable: Name of the variable that you want to write to the file.

Note for relative files: If the contents of this variable does not match the length of the record that is specified in the Len clause of the Open statement, the space between the end of the newly written record and the next record is padded with existing data from the file that you are writing to.

Nota para ficheiros binarios: O contido das variábeis escríbese na posición especificada, e o apuntador do ficheiro insírese directamente despois do último byte. Non permanece ningún espazo entre os rexistros.

### Exemplo:

      Sub ExampleRandomAccess
          Dim iNumber As Integer
          Dim sTexto As Variant REM Debe ser unha variante
          Dim aFile As String
          aFile = "C:\Users\ThisUser\data.txt"
          iNumber = Freefile
          Open aFile For Random As #iNumber Len=32
          Seek #iNumero,1 REM Position at beginning
          Put #iNumber, , "This is the first line of text" ' Fill line with text
          Put #iNumber, , "This is the second line of text"
          Put #iNumber, , "This is the third line of text"
          Seek #iNumber,2
          Get #iNumber, , sText
          Print sText
          Close #iNumber
          iNumber = Freefile
          Open aFile For Random As #iNumber Len=32
          Get #iNumber, 2, sText
          Put #iNumber, , "This is a new text"
          Get #iNumber, 1, sText
          Get #iNumber, 2, sText
          Put #iNumber, 20, "This is the text in record 20"
          Print Lof(#iNumber)
          Close #iNumber
      End Sub

      Sub ExampleRandomAccess
          Dim iNumber As Integer
          Dim sText As Variant ' Must be a variant
          Dim aFile As String
          aFile = "~/data.txt"
          iNumber = Freefile
          Open aFile For Random As #iNumber Len=32
          Seek #iNumber,1 ' Position at beginning
          Put #iNumber, , "This is the first line of text" ' Fill line with text
          Put #iNumber, , "This is the second line of text"
          Put #iNumber, , "This is the third line of text"
          Seek #iNumber,2
          Get #iNumber, , sText
          Print sText
          Close #iNumber
          iNumber = Freefile
          Open aFile For Random As #iNumber Len=32
          Get #iNumber, 2, sText
          Put #iNumber, , "This is a new text"
          Get #iNumber, 1, sText
          Get #iNumber, 2, sText
          Put #iNumber, 20, "This is the text in record 20"
          Print Lof(#iNumber)
          Close #iNumber
      End Sub

Temas relacionados

Instrución Close

Instrución Get

Instrución Open

Precisamos da súa axuda!