Put# Statement

Writes a record to a relative file or a sequence of bytes to a binary file.

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.


Syntax:

Put Statement diagram


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

Parameters:

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.

For binary files (binary access), the position of the byte in the file where you want to start writing.

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.

Note for binary files: The contents of the variables are written to the specified position, and the file pointer is inserted directly after the last byte. No space is left between the records.

Example:

Example:


Sub ExampleRandomAccess
    Dim iNumber As Integer
    Oznaciti sText kao varijantu REM mora biti varijanta
    Dim aFile As String
    aFile = "c:\data.txt"
    iNumber = Freefile
    Open aFile For Random As #iNumber Len=32
    Traziti #iBroj,1 REM pozicija na pocetku
    Staviti #iBroj,, "Ovo je prvi red teksta" REM ispuniti sa tekstom
    Staviti #iBroj,,"Ovo je novi red teksta"
    Staviti #iBroj,,"Ovo je novi red teksta"
    Seek #iNumber,2
    Get #iNumber,,sText
    Print sText
    Close #iNumber
    iNumber = Freefile
    Open aFile For Random As #iNumber Len=32
    Get #iNumber,2,sText
    Staviti #iBroj,,"Ovo je novi red teksta"
    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

Please support us!