PUT([#filenumber [,recnumber] ,varname) |
Writes data from a record into a text file. |
filenumber | The number of the file (Integer). |
recnumber | (Optional) The record number in a random file or byte number in a binary file where the writing should occur. |
varname | (Optional) The variable whose contents will be written to the file. |
REMARKS |
* This statement can only be used with files opened with Binary or Random access. * You can use the OPEN statement to open a file. * You can use the GET statement to read data from a file to a record. * For the Microsoft documentation refer to learn.microsoft.com |
Type recRecord
ID As Integer
Text As String * 10
End Type
Sub Example()
Dim mRecord As recRecord
VBA.Open "C:\temp\MyText2.txt" For Random As #1 Len = Len(mRecord)
mRecord.ID = 10
mRecord.Text = "text 111"
Put #1, 1, mRecord
mRecord.ID = 20
mRecord.Text = "22222"
Put #1, 2, mRecord
mRecord.ID = 30
mRecord.Text = "33 text 33"
VBA.Put #1, 3, mRecord
VBA.Close #1
VBA.Open "C:\temp\MyText2.txt" For Random As #1 Len = Len(mRecord)
Get #1, 1, mRecord
Debug.Print mRecord.ID & " - " & mRecord.Text
Get #1, 2, mRecord
Debug.Print mRecord.ID & " - " & mRecord.Text
Get #1, 3, mRecord
Debug.Print mRecord.ID & " - " & mRecord.Text
VBA.Close #1
End Sub
© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited Top