GET

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

Reads data from a text file into a record.


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 name of the variable you want to read to

REMARKS
* For an example refer to the page under Reading Text Files
* This statement can only be used with files opened with Binary or Random access.
* You can use the CLOSE statement to to close a text file.
* You can use the GET statement to read data from a text file into a record.
* You can use the OPEN statement to open a file.
* You can use the PRINT statement to write display-formatted data to a sequential file.
* You can use the PUT statement to write data from a record to a file.
* 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