Get Statement

Reads data into a variable from an open file on the disk.

Syntax

Get [#]filenumber, [recnumber], varname

The Get statement syntax contains the following parts:

Элемент Описание
filenumber Requied, any valid file number.
recnumber Optional, of Variant (Long) type. Sets the record number (for files in the Random mode) or byte number (for files in the Binary mode) from which to start reading.
varname Required, a valid name of the variable in which the read data will be stored.

Remarks

Data, read using the Get statement are normally written to a file with the Put statement.
Number 1 corresponds to the first record (or byte) of the file, number 2 - to the second one, and so on. If the recnumber argument is omitted, reading starts from the record (byte) to which the pointer has been moved after the most recent Get or Put operation (or where it has been moved after the last Seek function call). The comma separators are required, for instance:

Get #4,,FileBuffer

The following rules apply to the files, opened in the Random mode:

The above rules apply to files opened in the Binary mode, except of the following:

VarString = String(10," ")
Get #1,,VarString

Example

In this example the Get statement is used for reading data from a file into a variable. It's assumed that the TESTFILE file contains 5 records (see the example of using Put).

Dim sName As String * 20, nPosition ' Declares variable.

' Opens file for random access.
Open "TESTFILE" For Random As #1 Len = 21

' Reads from the file using the Get statement.
nPosition = 3 ' Determines record number.
Get #1, nPosition, sName ' Reads the third record.
MsgBox(sName)
Close #1 ' Closes file.

See Also

Recording data in a file, Put Statement, Open Statement, Seek Function, VarType Function