PUT$ statement  

Purpose

Writes an ANSI string to a file opened in binary mode.

Syntax

PUT$ [#] filenum&, StrgExpr

Remarks

PUT$ first evaluates the string expression.  If it results in a WIDE Unicode string, it is converted to ANSI byte characters.  PUT$ then writes the ANSI string to the file specified by FileNum& at the current file pointer position.  GET$, PUT$, and SEEK provide a low-level alternative to sequential and random-access file processing techniques, allowing you to deal with files on a byte by byte basis.

File filenum& must have been opened in binary mode.  Bytes are written starting at the current file pointer position, which can be set with the SEEK statement.  When the file is first opened, the pointer is at the beginning of the file (position 1, by default, unless BASE=0 was specified in the OPEN statement).  After PUT$, the file pointer position is automatically advanced to the point which immediately follows the just written data.  You can use SEEK to retrieve or change the file pointer position.

Filenum&

The file number under which the file was opened.

StrgExpr

A string expression which is written to the file.

See also

GET, GET$, GET$$, OPEN, PUT, PUT$$, SEEK functionSEEK statementSETEOF, WRITE#

Example

' Open a binary file and write the alphabet to it

OPEN "SEEK.DTA" FOR BINARY AS #1 BASE = 1

FOR I& = ASC("A") TO ASC("Z")   ' 65 TO 90

  PUT$ #1, CHR$(I&)

NEXT

CLOSE #1