PUT$ statement

Purpose: PUT$ writes binary data to a file. The file must be opened in BINARY mode and the SEEK statement must be used to set the next write position in the file.


 Syntax:

 PUT$ hFile, Buffer$, Number_Of_Bytes_To_Put%

 Parameters:

  • hFile Name of handle to file opened in BINARY mode to which binary data will be written.
  • Buffer$ String containing binary data to be written to file.
  • Number_Of_Bytes_To_Put% Number of bytes to write to 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 GET$ statement.