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.


Syntax:

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

Parameters:

  • 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.

Example:


 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                               ' ************************** 
  
 CLS
 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
 PRINT A$                                '  and clean up after 
 CLOSE FP1                               '  ourselves. 
 KILL "JUNK.BIN"                       ' ************************** 
 

See also the SEEK statement and PUT$ statement.