on error goto handle
key off
cls

print  "      Extraction of record segments from fixed record length files"
print
beg:
input "Name of Input file ";a$
open a$ for input as #1
close #1
open a$  AS #1 LEN = 82
field #1, 82 as a$
ag:
input "Name of file to store extracted records ";b$
open b$ for output as #2
if b$=a$ then print "Cannot have same name for these files, try again":goto ag

cls
locate 5,1
print "1st and last record numbers to be extracted (not necessarily increasing).
print "To end cycle enter negative numbers  (maximum cycles is 10)"
print
cyc=1
segm:
if cyc=10 then cony
print "Segment ";cyc;": Start record no. " ;
x=pos(1):y=csrlin:input c(cyc)
locate y,x+10

print " End record no";:input d(cyc)

if c(cyc)<0 or d(cyc)<0 then cony

if c(cyc)<=d(cyc) then
y=csrlin
locate 25,15:     print "                     ";
locate y,1:incr cyc:goto segm
end if
y=csrlin
locate 25,15:beep:print "Selection not allowed";
CYC=CYC-1:goto segm
cony:
decr cyc
if cyc=0 then print "No extraction performed":end
cls
locate 10,10

print "Stations extracted: ";STN
for i = 1 to cyc
for j = c(i) to d(i)
if j>lof(1)/82 then exit for

get #1,j

print #2,mid$(a$,1,80)
if mid$(a$,80,1)="J" OR mid$(a$,80,1)="1" then
incr stn:locate 10,31:print stn;
end if
next j
next i
print #2,chr$(26);
print "job done"
end

handle:
if err=53 then print "Input file not available, try again":resume beg
end

