Get Statement

Description

Reads from an open disk file into a variable.

Syntax

Get [#]filenumber,[recnumber],varname

The Get statement syntax has these parts:

Part

Description

filenumber

Any valid file number.

recnumber

Record number (Random mode files) or byte number (Binary mode files) at which reading begins.

varname

Valid variable name into which data is read.


Remarks

The first record/byte in a file is at position 1, the second record/byte is at position 2, and so on. If you omit recnumber, the next record or byte (the one after the last Get or Put statement or the one pointed to by the last Seek function) is read. Delimiting commas must be included, for example:


Get #4,,FileBuffer

For files opened in Random mode, the following rules apply:

For files opened in Binary mode, all of the Random rules apply except that:

See Also

Open Statement, Put Statement, Type Statement, VarType Function.

Example

This example uses the Get statement to read data from a disk file into a variable. For purposes of this example, assume that TESTFILE is a file containing five records of the user-defined type Record.


Type Record    ' Define user-defined type.
    ID As Integer
    Name As String * 20
End Type
Dim MyRecord As Record    ' Declare variable.
' Open sample file for random access.
Open "TESTFILE" For Random As #1 Len = Len(MyRecord)
' Read the sample file using the Get statement.
Position = 3    ' Define record number.
Get #1, Position, MyRecord    ' Read third record.
Close #1    ' Close file.