PUT

PUT([#] filenumber [,recnumber] ,varname)

Writes data from a record into a text file.


filenumberThe 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
* For an example refer to the page under Writing Text Files
* 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.
* You can use the PRINT statement to write data to a file opened with Sequential access (display-formatted).
* You can use the SEEK statement to reposition where the next operation in a file will occur.
* 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
   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"
   Put #1, 3, mRecord
   Close #1

   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
   Close #1
End Sub

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top