GET$ statement  

Purpose

Read an ANSI string from a file opened in binary mode.

Syntax

GET$ [#] filenum&, Count&, StrgVar

filenum&

The file number under which the file was opened.

Count&

Specifies how many bytes to read.

StrgVar

The string variable which receives the data.  It can be a dynamic string, fixed-length string, nul-terminated string, or field string.  StrgVar may be either ANSI or WIDE.  If it is a WIDE variable, the data is automatically converted to WIDE Unicode before it is assigned.

Remarks

GET$ reads Count& characters from file number filenum&, and assigns them to StrgVar.  GET$ and PUT$ 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.  Characters are read 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 GET$, the file pointer position is automatically advanced to the position immediately following the data read.

See also

EOF, GET, GET$$, INPUT#, LINE INPUT#, LOF, OPEN, PRINT#, PUT, PUT$, PUT$$, SEEK, WRITE#

Example

' Open binary file, write the alphabet A-Z to it

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

FOR I& = 65 TO 90

  PUT$ #1, CHR$(I&)

NEXT I&

 

' Now read five characters at a time from the file,

' starting at different pointer positions

FOR I& = 0 TO 20 STEP 5

  SEEK #1, I&

  GET$ #1, 5, TempString$

  x$ = "Starting at position" + STR$(I&) + $SPC + $DQ + TempString$ + $DQ

NEXT I&

CLOSE #1

Result

Starting at position  0 "ABCDE"

Starting at position  5 "FGHIJ"

Starting at position 10 "KLMNO"

Starting at position 15 "PQRST"

Starting at position 20 "UVWXY"