Chapter
10
I
BASIC Keywords
VARPTR
Function
VARPTR
(variable)
VARPTR
([#]buffer)
Returns the offset into BASIC’s data segment
of
a variable
or
a
disk buffer.
Variable
is
a
numeric or string variable.
Buffer
is the number assigned
to
the file when you opened it.
The number sign is optional. It is provided
for
compatibility with
other BASICs.
VARPTR can help you locate a value in memory. When used
with
Variable,
it returns the address of the
first
byte
of
data
identified with
variable.
See the section “How Variables
are
Stored” in Chapter
11
for
the format.
If the
variable
you specify has not been assigned
a
value, an “Il-
legal function call” occurs.
When used with sequential access files, VARPTR returns the
starting address
of
the disk buffer. When used with direct access
files, VARPTR returns the address
of
the FIELD buffer.
If you specify
a
buffer
that was not allocated when loading
BASIC, a “Bad file number” error occurs. (See Chapter
2
for
in-
formation on how
to
load BASIC.)
The offset returned is an integer in the range
-32768
to
32767.
It is always an offset into BASIC’s data segment, regardless
of
whether you have executed
a
DEF SEG to change the segment.
VARPTR is used primarily to pass
a
value to an assembly
language subroutine via USR. Since VARPTR returns an offset
that indicates where the value
of
a variable is stored,
you
can
pass this address
to
an assembly-language subroutine as the ar-
gument
of
USR. The subroutine can then extract the contents
of
the variable with the help
of
the address that you have supplied
to it.
If VARPTR returns a negative address, add it
to
65536
to obtain
the actual address.
335