Purpose
Reads from a file opened in Binary or Random access mode.
Syntax
Get [#] filenum, [ position ], var_name
filenum is the number of a file opened through an Open File statement.
position is a LargeInt value, indicating the desired file position to read from.
var_name is the name of a variable where MapBasic will store results.
Description
The Get statement reads from an open file. The behavior of the Get statement and the set of parameters which it expects are affected by the options specified in the preceding Open File statement.
If the Open File statement specified Random file access, the Get statement's Position clause can be used to indicate which record of data to read. When the file is opened, the file position points to the first record of the file (record 1). A Get automatically increments the file position, and thus the Position clause does not need to be used if sequential access is being performed. However, you can use the Position clause to set the record position before the record is read.
If the Open File statement specified Binary file access, one variable can be read at a time. What data is read depends on the byte-order format of the file and the var_name variable being used to store the results. If the variable type is integer, then 4 bytes of the binary file will be read, and converted to a MapBasic variable. Variables are stored the following way:
Variable Type | Storage In File |
---|---|
Logical | One byte, either 0 or non-zero. |
SmallInt | Two byte integer. |
Integer | Four byte integer. |
Float | Eight byte IEEE format. |
String | Length of string plus a byte for a 0 string terminator. |
Date | Four bytes: SmallInt year, byte month, byte day. |
Other data types | Cannot be read. |
With Binary file access, the position parameter is used to position the file pointer to a specific offset in the file. When the file is opened, the position is set to one (the beginning of the file). As a Get is performed, the position is incremented by the same amount read. If the Position clause is not used, the Get reads from where the file pointer is positioned.
If a file was opened in Binary mode, the Get statement cannot specify a variable-length string variable; any string variable used in a Get statement must be fixed-length.
See Also: