Post by DARKNIGHT on Jan 30, 2024 20:46:24 GMT -5
hello All,
I am trying to learn how to use random access files. I think I pretty much have it down,
but the only problem is, if I select a non existent record #, I get the standard LB EOF error.
and my progam crashes.
my question is: can I use the EOF statement in Random access ?
is there another method I can use to detect EOF otherwise?thank you in advance
here is my code:
Rem Random Access test 3
OPEN "members.dat" FOR RANDOM AS #1 LEN=76
FIELD #1,_' set up the fields for file opened as #1
30 AS Name$,_ ' 1st 30 bytes contains Name$, string
40 AS Address$,_ ' 2nd 40 bytes contains Address$, string
6 AS IDnumber ' 3rd 6 bytes contains IDnumber, numeric
'gosub [Set_Data] *** Temp JSR to setup R.A files
[Fetch_Record]
locate 5,4:input"Enter Record # to search:";a
if a=0 then [Fetch_Record]
'
locate 5,7:print"======================================================================="
locate 5,8:print"| ID #: | NAME: | ADDRESS: |"
locate 5,9:print"======================================================================="
if eof(#1)<1 then [Err]
GET #1,a
'* Fill Form
locate 7,10:print IDnumber
locate 15,10:print Name$'
locate 38,10:print Address$
locate 10,20:input"Press 'Enter' to search again: -> ";r$
cls
gosub [Fetch_Record]
[Err]' NOTE: Have not found a good way to detect EOF state in RA
locate 5,6:print"<<< Record Not Found >>>"
for x=1 to 300000:next x
cls
gosub [Fetch_Record]
[Set_Data]' *** CREATES RECORDS- on first time use ***
for a=1 to 2
if a=1 then let Name$ = "John Q. Public": Address$ = "456 Maple Street, Anytown, USA":IDnumber = 9274
if a=2 then let Name$ = "Alfred R Jones":Address$ = "227 15th Av, New York New York, USA":IDnumber = 4365
PUT #1,a
next a
print"Records Written"
end
OPEN "members.dat" FOR RANDOM AS #1 LEN=76
FIELD #1,_' set up the fields for file opened as #1
30 AS Name$,_ ' 1st 30 bytes contains Name$, string
40 AS Address$,_ ' 2nd 40 bytes contains Address$, string
6 AS IDnumber ' 3rd 6 bytes contains IDnumber, numeric
'gosub [Set_Data] *** Temp JSR to setup R.A files
[Fetch_Record]
locate 5,4:input"Enter Record # to search:";a
if a=0 then [Fetch_Record]
'
locate 5,7:print"======================================================================="
locate 5,8:print"| ID #: | NAME: | ADDRESS: |"
locate 5,9:print"======================================================================="
if eof(#1)<1 then [Err]
GET #1,a
'* Fill Form
locate 7,10:print IDnumber
locate 15,10:print Name$'
locate 38,10:print Address$
locate 10,20:input"Press 'Enter' to search again: -> ";r$
cls
gosub [Fetch_Record]
[Err]' NOTE: Have not found a good way to detect EOF state in RA
locate 5,6:print"<<< Record Not Found >>>"
for x=1 to 300000:next x
cls
gosub [Fetch_Record]
[Set_Data]' *** CREATES RECORDS- on first time use ***
for a=1 to 2
if a=1 then let Name$ = "John Q. Public": Address$ = "456 Maple Street, Anytown, USA":IDnumber = 9274
if a=2 then let Name$ = "Alfred R Jones":Address$ = "227 15th Av, New York New York, USA":IDnumber = 4365
PUT #1,a
next a
print"Records Written"
end