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.


 Syntax:

 GET$ hFile, Buffer$, Number_Of_Bytes_To_Get%

 Parameters:

  • hFile Name of handle to file opened in BINARY mode from which binary data will be read.
  • Buffer$ String to receive binary data read from file.
  • Number_Of_Bytes_To_Get% Number of bytes to read from file.

Example:


 DIM    A$ * 5000

 ' **************************
 '  Create a data file
 '  to explore
 ' **************************

 OPEN  "DATA.BIN" FOR BINARY NEW AS FP1
 A$ = REPEAT$(500,CHR$(248)) & "Hello"
 PUT$  FP1,A$,LEN(A$)
 CLOSE FP1

 ' **************************
 '  Now lets read it,starting
 '  in the middle of the file
 '  reading 6 bytes at byte
 '  500 then going back and
 '  reading 1000 bytes from
 '  the beginning of the file
 ' **************************

 CLS
 OPEN  "DATA.BIN" FOR INPUT AS FP1
 SEEK   FP1,500
 GET$   FP1,A$,6
 PRINT  A$
 SEEK   FP1,0
 GET$   FP1,A$,1000
 PRINT
 PRINT
 PRINT  A$
 CLOSE  FP1

See also the SEEK statement and PUT$ statement.