Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
FIELD Statement Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
' This example uses the FIELD statement to define a random-access file
' buffer. 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 program then checks to see if Zip$, which contains
' the ZIP code, falls within a certain range; if it does, the complete
' address string is printed.
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
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 ' Clear the screen
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 "Drew Fletcher","1200 Liberty St.","Bow","WA","98232"
DATA "Lynn Edmark","123 B St.","Bellevue","WA","98005"
DATA "Laura Bennett","14900 123rd","Bothell","WA","98011"
DATA "Jeff Webb","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 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