GET$ statement

Purpose: GET$ reads binary data from a file. The file must be opened in BINARY mode and the SEEK statement must be used to set the next read position in the file.

VBA's GET reserved word can be used as an alias to BCX's GET$ statement.


 GET$ hFile AS FILE, _
   Buffer AS STRING, _
   Number_Of_Bytes_To_Get AS INTEGER


  • Data type: FILE
    hFile The handle of file opened in BINARY mode from which binary data will be read.
  • Data type: STRING
    Buffer The string to receive binary data read from file.
  • Data type: INTEGER
    Number_Of_Bytes_To_Get Number of bytes to read from file.


 DIM A$ * 5000
 OPEN "JUNK.BIN" FOR BINARY NEW AS FP1   ' ************************** 
 A$ = REPEAT$(500, CHR$(248)) & "Hello" '     Create a data file 
 PUT$ FP1, A$, LEN(A$)                  '         to explore 
 CLOSE FP1                               ' ************************** 
 OPEN "JUNK.BIN" FOR BINARY INPUT AS FP1 ' ************************** 
 SEEK  FP1, 500                         '  Now lets read it, 
 GET$  FP1, A$, 5                       '  Grab 5 bytes near end of file 
 A[5] = 0                              '  Null terminate A$ for safety 
 PRINT A$                                '  Display it 
 SEEK  FP1, 0                           '  go back to the beginning 
 GET$  FP1, A$, 1000                    '  of the file 
 PRINT A$                                '  and clean up after 
 CLOSE FP1                               '  ourselves. 
 KILL "JUNK.BIN"                       ' ************************** 

See also the SEEK statement and PUT$ statement.