bas7advr.hlp (
Topic list)
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.
VARPTR, VARSEG Functions Details
◄Syntax► ◄Details► ◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
VARPTR and VARSEG return the address of a variable (for numeric variables)
or the address of a string descriptor (for near string variables).
VARPTR(variablename)
VARSEG(variablename)
■ The argument variablename can be any BASIC variable, including a
record variable or record element.
Usage Notes
■ When variablename is a numeric variable, the VARPTR function returns
an unsigned integer (the offset of the variable within its segment).
■ When variablename is a numeric variable, the VARSEG function returns
an unsigned integer (the segment address of the variable).
■ When variablename is a string variable, VARSEG returns the segment
address of the variable, and VARPTR returns the offset address of
the variable.
■ If variablename is not defined before VARPTR or VARSEG is called,
the variable is created and its address is returned.
■ VARPTR and VARSEG are often used with Absolute, BLOAD, BSAVE,
Interrupt, PEEK, POKE, or when passing arrays to procedures written
in other languages.
Note on Mixed-Language Programming
■ Do not pass expanded memory arrays to non-BASIC procedures. (If
you start QBX with the /Ea switch, any of these arrays may be stored
in expanded memory:
- Numeric arrays < 16K in size
- Fixed-length string arrays < 16K in size
- User-defined-type arrays < 16K in size
■ If you want to pass arrays to non-BASIC procedures, first start QBX
without the /Ea switch. (Without the /Ea switch, no arrays are
stored in expanded memory.)
■ For more information on using expanded memory, see
◄Using Expanded Memory►.
Usage Notes
■ When using VARPTR or VARSEG to get the address of an array, use the
first element of the array as the argument:
DIM A(150)
.
.
.
ArrAddress=VARPTR(A(1))
■ You can use VARPTR alone to get the address of a numeric variable
stored in DGROUP. You must use both VARPTR and VARSEG to get the
complete address of a numeric variable stored in far memory.
■ It is not meaningful to use VARSEG and VARPTR for far strings, since
the format of the far strings' string descriptor is different from
the string descriptor for near strings. See the ◄StringAddress► for
routine information on locating the address of a far string's
string descriptor.
■ You cannot use VARPTR to get the address of a file's buffer.
Use the FILEATTR function to get information about a file.
■ Programs written in earlier versions of BASIC that used VARPTR to
access numeric arrays may no longer work. You must now use a
combination of VARPTR and VARSEG. For example, the following
QuickBASIC version 3.0 fragment no longer works correctly:
DIM Cube(675)
.
.
.
BSAVE "graph.dat",VARPTR(Cube(1)),2700
The fragment could be rewritten as follows to work in the current
version of BASIC:
DIM Cube(675)
.
.
.
' Change segment to segment containing Cube.
DEF SEG=VARSEG(Cube(1))
BSAVE "graph.dat",VARPTR(Cube(1)),2700
' Restore BASIC segment.
DEF SEG
■ The VARSEG function, combined with VARPTR, replaces the PTR86
subprogram used in previous versions of BASIC.
Programming With OS/2 Protected Mode
■ The VARSEG function returns the selector of the specified variable
or array.
Important
■ Because many BASIC statements move variables in memory, use the
values returned by VARPTR and VARSEG immediately after the functions
are used.