Put# Statement
Ghi một bản ghi vào một tập tin tương đối, hoặc ghi một dãy byte vào một tập tin nhị phân.
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.

Put [#]fileNum, [recordNum|filePos], variable
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.
Đối với tập tin nhị phân (truy cập nhị phân), vị trí của byte trong tập tin ở đó bạn muốn bắt đầu ghi.
variable: Name of the variable that you want to write to the file.
Ghi chú về tập tin tương đối: nếu nội dung của biến này không tương ứng với chiều dài của bản ghi được ghi rõ trong mệnh đề Len của câu lệnh Open, khoảng cách giữa kết thúc của bản ghi mới ghi và bản ghi kế tiếp được đệm bằng dữ liệu đã tồn tại từ tập tin vào đó bạn đang ghi.
Ghi chú về tập tin nhị phân: nội dung của các biến được ghi vào vị trí đã định, và con trỏ tập tin được chèn vào đúng phía sau byte cuối cùng. Không có khoảng cách nào giữa hai bản ghi.
Sub ExampleRandomAccess
Dim iNumber As Integer
Dim vanBan As Variant REM Phải là Variant
Dim aFile As String
aFile = "C:\Users\ThisUser\data.txt"
iNumber = Freefile
Open aFile For Random As #iNumber Len=32
Seek #soNguyen,1 REM Vị trí bắt đầu
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