Reads data from an open disk file into a variable.
Public Sub FileGetObject( _ ByVal FileNumber As Integer, _ ByRef Value As Object, _ Optional RecordNumber As Integer = -1 _ )
-or-
Overloads Public Sub FileGetObject( _ ByVal FileNumber As Integer, _ ByRef Value As Short, _ Optional RecordNumber As Integer = -1 _ )
-or-
Overloads Public Sub FileGetObject( _ ByVal FileNumber As Integer, _ ByRef Value As Integer, _ Optional RecordNumber As Integer = -1 _ )
-or-
Overloads Public Sub FileGetObject( _ ByVal FileNumber As Integer, _ ByRef Value As Single, _ Optional RecordNumber As Integer = -1 _ )
-or-
Overloads Public Sub FileGetObject( _ ByVal FileNumber As Integer, _ ByRef Value As Double, _ Optional RecordNumber As Integer = -1 _ )
-or-
Overloads Public Sub FileGetObject( _ ByVal FileNumber As Integer, _ ByRef Value As Decimal, _ Optional RecordNumber As Integer = -1 _ )
-or-
Overloads Public Sub FileGetObject( _ ByVal FileNumber As Integer, _ ByRef Value As Byte, _ Optional RecordNumber As Integer = -1 _ )
-or-
Overloads Public Sub FileGetObject( _ ByVal FileNumber As Integer, _ ByRef Value As Boolean, _ Optional RecordNumber As Integer = -1 _ )
-or-
Overloads Public Sub FileGetObject( _ ByVal FileNumber As Integer, _ ByRef Value As Date, _ Optional RecordNumber As Integer = -1 _ )
-or-
Overloads Public Sub FileGetObject( _ ByVal FileNumber As Integer, _ ByRef Value As System.Array, _ Optional RecordNumber As Integer = -1, _ Optional ArrayIsDynamic as Boolean = False _ )
-or-
Overloads Public Sub FileGetObject( _ ByVal FileNumber As Integer, _ ByRef Value As String, _ Optional RecordNumber As Integer = -1, _ Optional StringIsFixedLength as Boolean = False _ )
The FileGetObject function is used in place of FileGet to avoid ambiguities at compile time if type Object is returned rather than another type, such as Integer, Long, Short, and so forth.
If you intend to write out the Variant type, FileGetObject is required. When in doubt, if you are using an object for the second parameter, it is always safer to use FilePutObject and FileGetObject.
FileGetObject is only valid in Random and Binary mode.
Data read with FileGetObject is usually written with FilePutObject.
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 RecordNumber, FileGetObject reads the record or byte after the last FileGetObject or FilePutObject function (or pointed to by the last Seek function).
For files opened in Random mode, the following rules apply:
The descriptor specifies the rank of the array, the size, and the lower bounds for each rank. Its length equals 2 plus 8 times the number of dimensions, that is, 2 + 8 * NumberOfDimensions. The record length specified by the RecordLength parameter in the FileOpen function must be greater than or equal to the sum of all the bytes required to write the array data and the array descriptor. For example, the following array declaration requires 118 bytes when the array is written to disk:
Dim MyArray(4,9) As Integer
The 118 bytes are distributed as follows: 18 bytes for the descriptor (2 + 8 * 2), and 100 bytes for the data (5 * 10 * 2).
For files opened in Binary mode, all of the Random rules apply, except:
FileGetObject reads variable-length strings that aren't elements of structures without expecting the two-byte length descriptor. The number of bytes read equals the number of characters already in the string.
The following example reads a record into a test file and then retrieves it.
Dim c As String FileSystem.FileOpen(1, "test.dat", OpenMode.Binary) FileSystem.FilePutObject(1, "ABCDEF") FileSystem.Seek(1, 1) FileSystem.FileGetObject(1, c) System.Console.WriteLine(c) FileSystem.FileClose(1)
FilePut Function | FileOpen Function | Seek Function |