Difference between revisions of "GET"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 4: Line 4:
  
 
{{PageSyntax}}
 
{{PageSyntax}}
:: GET #''filenumber%'', [''position''], ''read_variable''
+
:: '''GET #''filenumber%'',''' [''position''][, {''holdingvariable''|''holdingarray()''}]
  
  
  
* File/port number is the number used in the [[OPEN]] AS statement.  
+
* File/port number is the file number used in the [[OPEN]] AS [[BINARY]] or [[RANDOM]] statement.  
* The [[INTEGER]] or [[LONG]] byte or record ''position'' is the byte in a [[BINARY]] file or the record in a [[RANDOM]] file.
+
* The [[INTEGER]] or [[LONG]] byte ''position'' in a [[BINARY]] file or the record ''position'' in a [[RANDOM]] file '''must be greater than zero'''.
* The ''position'' can be omitted if the GETs are consecutive or when creating a new file.
+
* The ''position'' can be omitted if the GETs are consecutive based on the ''holding variable'' [[TYPE]] byte size.
 
* The first file position is 1. This may require adding one to an offset value when documentation uses that position as 0.
 
* The first file position is 1. This may require adding one to an offset value when documentation uses that position as 0.
 
* GET does NOT require a record position or read variable when using a [[FIELD]] statement!
 
* GET does NOT require a record position or read variable when using a [[FIELD]] statement!
* The variable value is any string or number type or a [[TYPE]] or [[FIELD]] variable.
+
* The ''holding variable'' value is any string or numerical type or a [[TYPE]] or [[FIELD]] variable.
* '''QB64''' can GET the entire data contents of an array from a [[PUT]] array file.
+
* '''QB64''' can GET the entire data contents to a ''holding array''(include brackets) 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 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 the data should be [[PUT]] into a program or another file.
  
  

Revision as of 16:34, 26 August 2012

The GET # file or port device statement reads data by bytes or record positions.


Syntax

GET #filenumber%, [position][, {holdingvariable|holdingarray()}]


  • File/port number is the file number used in the OPEN AS BINARY or RANDOM statement.
  • The INTEGER or LONG byte position in a BINARY file or the record position in a RANDOM file must be greater than zero.
  • The position can be omitted if the GETs are consecutive based on the holding variable TYPE byte size.
  • The first file position is 1. This may require adding one to an offset value when documentation uses that position as 0.
  • GET does NOT require a record position or read variable when using a FIELD statement!
  • The holding variable value is any string or numerical type or a TYPE or FIELD variable.
  • QB64 can GET the entire data contents to a holding array(include brackets) 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 the data should be PUT into a program or another file.


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.


Example 3: Restoring array data from a BINARY file using GET # in QB64 only.

DIM myarray(80000) AS INTEGER OPEN "myfile.ext" FOR BINARY AS #1 GET #1, , myarray() CLOSE #1

Note: The file data must have been previously stored in the file using PUT # the same way!


See also:



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page