Difference between revisions of "GET"
|Line 3:||Line 3:|
:::''Syntax:'' GET #''filenumber%'', [''position
:::''Syntax:'' GET #''filenumber%'', [''position''], ''read_variable''
Revision as of 21:00, 29 April 2011
The GET # file or port device statement reads data by bytes or record positions.
- Syntax: GET #filenumber%, [position], read_variable
- File/port number is the number used in the OPEN AS statement.
- The INTEGER or LONG byte or record position is the byte in a BINARY file or the record in a RANDOM file.
- The position can be omitted if the GETs are consecutive or when creating a new file.
- The variable value is any string or number type or a TYPE or FIELD variable.
- QB64 can GET the entire data contents of an array from a PUT array file.
- GET can ignore the EOF statement and return bad data when transferring data to another file! Always check for EOF after a GET to see if it should be PUT.
- GET does NOT require a record position or read variable when using a FIELD statement!
Example 1: Checking for End of File before transferring individual GET data.
DO UNTIL EOF(1) GET #1, , value% IF NOT(EOF(1)) THEN PUT #2, , value% LOOP
Example 2: Using a TYPE record variable to read a TYPE record(Contact).
OPEN file$ FOR RANDOM as #1 LEN = LEN(Contact) IF record% <= LOF(1) \ LEN(Contact) THEN GET #1, record%, Contact CLOSE #1
Note: The Contact record contains all of the DOT variable types listed in the TYPE.
Note: The file data must have been previously stored in the file using PUT # the same way!