Liberty BASIC Help Online

FIELD #h, list...
 
FIELD #handle, length1 as varName, lenght2 as varName, . . .
 
Description:
FIELD is used with an OPEN "filename.ext" for random as #handle statement to specify the fields of data in each record of the opened file.  For example in this program FIELD sets up 6 fields of data, each with an appropriate length, and associates each with a string variable that holds the data to be stored in that field:
 
  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
 
[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
  put #cust, recNumber
 
  confirm "Enter more records?"; yesNo$   ' ask whether to enter more records
  if yesNo$ = "yes" then [inputLoop]
 
  close #cust   ' end of program, close file
  end
 
Notice that Liberty BASIC permits the use of numeric variables in FIELD (eg. age), and it allows you to 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  Random FilesPUT and GET
 


Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/