Put# Statement

Escribe un registro en un archivo relativo o una secuencia de bytes en un archivo binario.

tip

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.


Sintaxis:

Put Statement diagram

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 archivos binarios (acceso binario), la posición del byte del archivo en que se desee empezar a escribir.

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

Nota para archivos relativos: Si el contenido de esta variable no coincide con la longitud del registro que se especifica en la cláusula Len de la instrucción Open, el espacio entre el final del registro escrito recientemente y el siguiente se rellena con los datos existentes del archivo al que está escribiendo.

Nota para archivos binarios: El contenido de las variables se escribe en la posición especificada y el puntero del archivo se inserta directamente después del último byte. No se deja espacio entre los registros.

Ejemplo:

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

¡Necesitamos su ayuda!