FIELD
Jump to navigation
Jump to search
![]() |
![]() |
![]() |
![]() |
Description
- A FIELD is a variable that is given a name and size and identifies a piece of data that is part of a record in a random access file (RAF). All records in a file are structurally identical; They all have the same FIELDs.
- See also, GET, PUT, and Random access files.
Syntax
- field #handle, length1 as varName, length2 as varName, . . .
Hints
- FIELDs must be defined before a RAF can be accessed. They are defined with a name and a size - the number of characters to allow for the data that FIELD will hold. The sum of the sizes of all of the fields make up the length of a record. The length is assigned to the keyword "len" at the end of the Open "fileName" statement. The value of "len" must be equal to the sum of the field sizes.
- You cannot create FIELDS with sum of the field sizes more then 65536 bytes.
Example
' open a random access file open "custdata.001" for random as #cust len = 70 ' define the field variables field #cust, 20 as name$,_ 20 as street$,_ 15 as city$,_ 2 as state$,_ 10 as zip$,_ 3 as age [inputLoop] input "Name >"; name$ input "Street >"; street$ input "City >"; city$ input "State >"; state$ input "Zip Code >"; zip$ input "Age >"; age ' ask if the data is entered correctly confirm "Is this entry correct?"; yesNo$ if yesNo$ = "no" then [inputLoop] ' add 1 to the record # and put the record recNumber = recNumber + 1 put #cust, recNumber ' ask whether to enter more records confirm "Enter more records?"; yesNo$ if yesNo$ = "yes" then [inputLoop] ' end of program, close file close #cust end
Useful Procedures
' Place a useful function or sub using this keyword here