Copyright 2008 Shoptalk Systems

FIELD #handle, length1 as varName, length2 as varName, . . .

Description:

Used with a file opened for random access, the FIELD statement specifies the fields of data in each record of the opened file. For example in this program a FIELD statement sets up 6 fields of data, each with an appropriate length, and associates each with a variable that holds the data to be stored in that field:

[inputLoop]
  input "Name >"; name$
  input "Street >"; street$
  input "City >"; city$
  input "State >"; state$
  input "Zip Code >"; zip$
  input "Age >"; age
  confirm "Is this entry correct?"; yesNo$ 'ask if the data is entered correctly
  if yesNo$ = "no" then [inputLoop]
  recNumber = recNumber + 1 'add 1 to the record # and put the record

  open "custdata.001" for random as #cust len = 70 'open as random access
    field #cust, 20 as name$, 20 as street$, 15 as city$, 2 as state$, 10 as zip$, 3 as age
    put #cust, recNumber
  close #cust 'close file

  confirm "Enter more records?"; yesNo$ 'ask whether to enter more records
  if yesNo$ = "yes" then [inputLoop]
  end

Notice that the use of both string and numeric variables in FIELD (eg. age) is permitted.  You can PUT and GET with both string and numeric variables, automatically, without needing LSET, RSET, MKI$, MKS$, MKD$, CVI, CVS, & CVD that are required with Microsoft BASICs.

Note: See also PUT and GET