Tandy 1000 Basic Reference Manual page 212

Hide thumbs Also See for 1000:
Table of Contents

Advertisement

Chapter 10 I
BASIC
Keywords
LOF
Function
LOF
(
buffer)
Returns the length of the file in bytes.
Buffer
is the number assigned to the file when you opened it.
Example
Y
=
L O F ( 5 )
assigns the length of the file in bytes to variable
Y
Sample Programs
During direct access to a n existing file, you often need a way to
know when you have read the last valid record. LOF provides a
way:
1 5 4 0 OPEN "R",
1 ,
" u n k n o w n . t x t " ,
1 2 8
1 5 5 0 F I E L D 1 ,
1 2 8 AS A $
1 5 6 0 RCNUM%
=
1
' S T A R T
AT B E G I N N I N G OF F I L E
1 5 7 0 R C S I Z %
=
1 2 8
' S E T
RECORD S I Z E
1 5 8 0 I F RCNUM%
*
R C S I Z %
>
L O F ( 1 )
GOTO 1 6 4 0
1 5 9 0
'CHECK
FOR END OF F I L E
1 6 0 0 G E T 1 ,
RCNUMX 'RECORD NUM.
TO B E ACCESSED
1 6 1 0 P R I N T A S
1 6 2 0 RCNUM%
=
RCNUM%
+
1 ' I N C R E M E N T RECORD NUM
1 6 3 0 GOTO 1 5 8 0
1 6 4 0 CLOSE
If you attempt to
GET
record numbers beyond the end-of-file,
BASIC gives you a n error.
These lines use LOF to determine where to start adding when
you want to add to the end of a file:
1 7 0 0 RCNUM%
=
( L O F C 1 )
/ R C S I Z % )
+
1
1 7 2 0
' H I G H E S T E X I S T I N G RECORD
1 7 2 0 P U T 1 , RCNUM%
'ADD
N E X T RECORD
210

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents