Put# Statement

레코드를 상대 파일에 쓰거나 바이트 시퀀스를 이진 파일에 씁니다.

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.

이진 파일(이진 액세스)의 경우, 쓰기를 시작할 파일의 바이트 위치입니다.

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

상대 파일에 대한 참고 사항: 이 변수의 내용이 Open 문의 Len 절에 지정된 레코드 길이와 일치하지 않을 경우 새로 기록된 레코드의 끝 부분과 다음 레코드 사이의 공백이 쓰려는 파일의 기존 데이터로 채워집니다.

이진 파일에 대한 참고 사항: 변수 내용이 지정한 위치에 기록되고 마지막 바이트의 바로 뒤에 파일 포인터가 삽입됩니다. 레코드 간에 공백이 남지 않습니다.

Example:

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

Please support us!