VARPTR
The VARPTR function returns an INTEGER value that is the offset part of the variable or array memory address within it's segment.
Syntax
- offset% = VARPTR(variable_name[(reference_index%)])
- If variablename is not defined before VARPTR or VARSEG is called, the variable is created and it's address is returned.
- When using VARPTR inside a SUB or FUNCTION, then never directly use it on passed parameters, as these are no variables but just values on the function stack.
- If you need to do this, then move the respective parameter over into a local variable first and then call VARPTR on that variable instead of the parameter directly.
- Reference index is used to set the offset address of an array index, not necessarily the lowest index.
- When a string variable, VARPTR returns the offset address location of the first byte of the string.
- Because many QBasic statements change the locations of variables in memory, use the values returned by VARPTR and VARSEG immediately after the functions are used!
- Integer array sizes are limited to 32767 elements when using VARPTR in QB and QB64!. Create a larger array using _BYTE. Example: DIM SHARED Memory (65535) AS _UNSIGNED _BYTE
- Warning: DEF SEG, VARSEG , VARPTR, PEEK or POKE access QB64's emulated 16 bit conventional memory block!
- It is highly recommended that QB64's _MEM memory system be used to avoid running out of memory.
See also