Get
This method reads data from an open disk file into a variable.
Syntax
file.Get Data, [Recnumber]
Parameters
- file
- Reference to a File control.
- Data
- Required. Variant variable into which data is read.
- Recnumber
- Optional. Variant. Record number at which reading begins. For files opened in binary mode, Recnumber specifies the byte position.
Return Value
None.
Remarks
Data read with the Get method usually is written to a file with the Put method.
The first record or byte in a file is at position 1, the second record or byte is at position 2, and so on. If you omit Recnumber, the next record or byte following the last Get or Put method (or pointed to by the last Seek function) is read.
For files opened in Random mode, the following rules apply:
- If the length of the data being read is less than the length specified in the Len clause of the Open method, Get reads subsequent records on record-length boundaries. The space between the end of one record and the beginning of the next record is padded with the existing contents of the file buffer. Because the amount of padding data cannot be determined with any certainty, it is generally advisable to match the record length with the length of the data being read.
- If Data is a Variant of numeric type, Get reads 2 bytes identifying the VarType of the Variant and then reads the data that goes into the variable. For example, when reading a Variant of VarType 3, Get reads 6 bytes: 2 bytes identifying the Variant as VarType 3 (Long) and 4 bytes containing the Long data. The record length specified by the Len clause in the Open method must be at least 2 bytes greater than the actual number of bytes required to store the variable.
- You can use the Get method to read a Variant array from a disk, but you cannot use Get to read a scalar Variant containing an array. You also cannot use Get to read objects from a disk.
- If the variable being read into is a Variant of VarType 8 (String), Get reads 2 bytes identifying the VarType and 2 bytes indicating the length of the string. Then it reads the string data. The record length specified by the Len clause in the Open method must be at least 4 bytes greater than the actual length of the string.
- If the variable being read into is a dynamic array, Get reads a descriptor whose length equals 2 plus 8 times the number of dimensions, that is, 2 + 8 * NumberOfDimensions. The record length specified by the Len clause in the Open method must be greater than or equal to the sum of all the bytes required to read the array data and the array descriptor.
For files opened in Binary mode, the Len clause in the Open method has no effect. Get reads all variables from a disk contiguously; that is, with no padding between records.