Purpose |
Read a
|
Syntax |
GET$ [#] filenum&, Count&, sVar$ |
Remarks |
The GET$ statement has the following parts: |
filenum& |
Is the file number under which the file was opened. |
Count& |
Specifies how many bytes to read. |
sVar$ |
The string variable to read the data into. |
Remarks |
GET$ reads Count& characters from file number filenum&, and assigns them to sVar$. 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 (unless the LEN clause is used in the corresponding OPEN statement, position 1 is used by default). After GET$, the file pointer position will have been advanced by Count& bytes. 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. |
See also |
EOF, GET, INPUT#, LINE INPUT#, LOF, OPEN, PRINT#, 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 |
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" |