The [[FIELD]] statement creates a [[STRING]] type definition for a [[RANDOM|random]]-access file buffer.
{{PageSyntax}}
: [[FIELD]] [#]{{Parameter|fileNumber&}}, {{Parameter|fieldWidth1%}} AS {{Parameter|variable1$}}[, {{Parameter|fieldWidthN%}} AS {{Parameter|variableN$}}]
{{PageDescription}}
* {{Parameter|fileNumber%}} is a file number used in the [[OPEN]] statement or a value from the [[FREEFILE]] function.
* Combined size of the {{Parameter|fieldWidth%}} parameters '''must not exceed the [[LEN]] = recordsize in the [[RANDOM]] [[OPEN]] statement''' or a [[ERROR Codes|"FIELD overflow" error]] will occur.
* Variables are limited to [[STRING]] types. Use [[TYPE]] instead of FIELD if you want to use numerical values.
* Once a [[FIELD]] is defined in a statement, [[GET]] can read and [[PUT]] can write data without placeholders or variables.
* [[LSET]], [[RSET]], [[PRINT (file statement)|PRINT #]], [[PRINT USING (file statement)|PRINT # USING]], and [[WRITE (file statement)|WRITE #]] can be used to place characters in the file buffer before a [[PUT]].
* All field definitions for a file are removed when the file is [[CLOSE|closed]] or [[RESET]] and all strings are set to null ("").
* '''Do not re-assign a field defined variable value or use it in an [[INPUT]] statement if you want the variable to remain a field'''.
{{PageExamples}}
''Example:'' Comparing a [[TYPE]] definition with a FIELD [[STRING|string]] definition. Demo using a [[TYPE]] definition to create a file:
{{CodeStart}}
{{Cl|TYPE}} ClientType
CName {{Cl|AS}} {{Cl|STRING}} * 30 '30 bytes
Address {{Cl|AS}} {{Cl|STRING}} * 30 '30 bytes
City {{Cl|AS}} {{Cl|STRING}} * 15 '15 bytes
State {{Cl|AS}} {{Cl|STRING}} * 2 ' 2 bytes
Zip {{Cl|AS}} {{Cl|STRING}} * 5 ' 5 bytes
{{Cl|END}} {{Cl|TYPE}} ' total size = 82 bytes
{{Cl|DIM}} Client {{Cl|AS}} ClientType
RecordLEN = {{Cl|LEN}}(Client) 'find the size of each TYPE record