qb45advr.hlp (Topic list)
FIELD Statement Programming Example
  QuickSCREEN      Details     Example      Contents      Index
──────────────────────────────────────────────────────────────────────────────
FIELD Statement Programming Example
 
This example illustrates a random-access file buffer with multiple
definitions:
  ■ In the first FIELD statement, the 67-byte buffer is broken up into
    five separate variables for name, address, city, state, and zip code.
  ■ In the second FIELD statement, the same buffer is assigned entirely
    to one variable, Plist$.
 
The remainder of this example checks to see if Zip$, which contains the zip
code, falls within a certain range; if it does, the complete address
string is printed.
 
' Example program for the FIELD statement
TYPE Buffer
   FuName AS STRING * 25
   Addr   AS STRING * 25
   City   AS STRING * 10
   State  AS STRING * 2
   Zip    AS STRING * 5
END TYPE
DIM RecBuffer AS Buffer
'********************************************************************
' NOTE: This part of the program creates a random-access
'       file for use by the second part of the program, which
'       demonstrates the FIELD statement
'********************************************************************
OPEN "MAILLIST.DAT" FOR RANDOM AS #1 LEN = LEN(RecBuffer)
CLS
RESTORE
READ FuName$, Addr$, City$, State$, Zip$
I = 0
DO WHILE UCASE$(FuName$) <> "END"
   I = I + 1
   RecBuffer.FuName = FuName$
   RecBuffer.Addr = Addr$
   RecBuffer.City = City$
   RecBuffer.State = State$
   RecBuffer.Zip = Zip$
   PUT #1, I, RecBuffer
   READ FuName$, Addr$, City$, State$, Zip$
   IF FuName$ = "END" THEN EXIT DO
LOOP
CLOSE #1
'
   DATA "Bob Hartzell","1200 Liberty St.","Bow","WA","98232"
   DATA "Alice Provan","123 B St.","Bellevue","WA","98005"
   DATA "Alex Landow","14900 123rd","Bothell","WA","98011"
   DATA "Walt Riley","33 Minnow Lake Road","Lyman","WA","98263"
   DATA "Georgette Gump","400 15th W.","Bellevue","WA","98007"
   DATA "END",0,0,0,0,0
'*********************************************************************
'This part of the program demonstrates the use of the FIELD statement
'*********************************************************************
' Define field and record lengths with constants.
CONST FU = 25, AD = 25, CT = 10, ST = 2, ZP = 5
CONST RECLEN = FU + AD + CT + ST + ZP
'
OPEN "MAILLIST.DAT" FOR RANDOM AS #1 LEN = RECLEN
FIELD #1, FU AS FuName$, AD AS Addr$, CT AS City$, ST AS State$, ZP AS Zip$
FIELD #1, RECLEN AS Plist$
 
GET #1, 1
' Read the file, looking for zip codes in the range 98000 to 98015.
DO WHILE NOT EOF(1)
   Zcheck$ = Zip$
   IF (Zcheck$ >= "98000" AND Zcheck$ <= "98015") THEN
      Info$ = Plist$
      PRINT LEFT$(Info$, 25)
      PRINT MID$(Info$, 26, 25)
      PRINT RIGHT$(Info$, 17)
      PRINT
   END IF
   GET #1
LOOP
CLOSE #1