Выполняет запись в файл с произвольным доступом или записывает последовательность байтов в бинарный файл.
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.
Для бинарных файлов (бинарный доступ) — байт, с которого необходимо начать запись.
variable: Name of the variable that you want to write to the file.
Для файлов с произвольным доступом: если содержимое этой переменной не совпадает с длиной записи, указанной в выражении Len инструкции Open, то пространство от конца новых записанных данных до следующей записи заполняется данными, уже существующими в этом файле.
Для бинарных файлов: содержимое переменных записывается в указанную позицию, а указатель позиции в файле устанавливается после последнего записанного байта без какого-либо пространства между записями.
Пример:
Sub ExampleRandomAccess
Dim iNumber As Integer
Dim sText As Variant REM Должно быть Variant
Dim aFile As String
aFile = "C:\Users\ThisUser\data.txt"
iNumber = Freefile
Open aFile For Random As #iNumber Len=32
Seek #iNumber,1 REM Позиция в начале
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 REM Должно быть Variant
Dim aFile As String
aFile = "~/data.txt"
iNumber = Freefile
Open aFile For Random As #iNumber Len=32
Seek #iNumber,1 REM Позиция в начале
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