reads a record from a random access file.
Get #n [[,record], varname]
Get% #n [[,record], varname]
n:integer expression; channel number
record:integer expression; record number
varname:variable aexp
Get # reads a record from an Random Access file through the channel n (from 0 to 511), previously opened with Open. record is an optional parameter and contains a value between 1 and the number of records within the file. If record is not specified the next record in file is always read. Otherwise the record specified in record is read.
The first record or byte in a file is at position 1, the second record or byte is at position 2, and so on. This can be changed using Option Base ,n
The second optional parameter varname is a variable of any type into which data is read. This syntax allows to use Get without a Field command, in a VB compatible manner. The length of this variable should be enough to hold a record (Len=).
Get% # reads from a file with a maximum size 2GB.
Global city$, i%, n$, name$, o$, postcode%, s$, strt$
OpenW # 1
Open App.Path & "\Addresses.DAT" for Random As # 1, Len = 64
Field # 1, 24 As name$, 24 As strt$, 4 At(V:postcode%), 12 As city$
//
For i% = 1 To 5
Input "NAME : ";n$
Input "Street : ";s$
Input "Postcode: ";postcode%
Input "City : ";o$
Lset name$ = n$
Lset strt$ = s$
Lset city$ = o$
Put # 1, i%
Cls
Next i%
Close # 1
//
Open App.Path & "\Addresses.DAT" for Random As # 1, Len = 64
Field # 1, 24 As name$, 24 As strt$, 4 At(V:postcode%), 12 As city$
//
For i% = 1 To 5
Get # 1, i%
Print "Record number: "; Str$(i%, 3)
Print "NAME : "; name$
Print "Street : "; strt$
Print "Postcode: "; postcode%
Print "City : "; city$
Next i%
Close # 1
Kill App.Path & "\Addresses.DAT" // Tidy-up line
A channel for the random access file is opened first. Next, the record is divided with Field into: 24 bytes for the name, 24 bytes for the street, four bytes for the postal code and 12 bytes for the city, which all together totals 64 bytes. The For...Next loop writes five records to the file ADDRESSES.DAT on drive C. And finally, these records are read in using Get and displayed on the screen again.
The functions Loc%(), Lof%(), Record%#, Seek%# etc. internally use 32 bits integers and are therefore limited to files with a file size upto 2 GB. The versions without % use 64-bit integers and allow access to larger files.
{Created by Sjouke Hamstra; Last updated: 26/11/2023 by James Gaite}