Q(uick)BASIC Function: VARPTR$
Quick View
VARPTR$
A memory function that returns a string representation of a variable's address for use in DRAW and PLAY statements
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- VARPTR$(commandstring$)
Description/Parameter(s)
commandstring$ | A string variable containing DRAW or PLAY commands. |
Example
Scale$ = "CDEFGAB"
PLAY "L16"
FOR i% = 0 TO 6
PLAY "O" + STR$(i%)
PLAY "X" + VARPTR$(Scale$)
NEXT i%
See also:
Syntax
- VARPTR$(variablename)
Description/Parameter(s)
The variablename is the name of a variable in the program.
If variablename is an array element, then the array must be dimensioned before the VARPTR$ function is used. The array must be an array of variable-length strings.
Note: | To guarantee correct results, use the value of VARPTR$ immediately after invoking the function. |
Differences from BASICA
- In QuickBASIC programs, VARPTR$ must be used in the DRAW and PLAY statements to execute substrings containing variables.
- BASICA supports both the VARPTR$ syntax and the syntax containing just the variable name.
Example
See the following programming examples that use the VARPTR$ function:⮜ DRAW statement example 2 ⮞⮜ PLAY statement example ⮞
See also:
Syntax
- VARPTR$(variablename)
Description/Parameter(s)
variablename | The name of a variable in the program. |
- If variablename is an array element, the dimensions for the array must be specified before VARPTR$ is used. The array must consist of variable-length strings.
Important
- To guarantee correct results, use the value returned by VARPTR$ immediately after invoking the function.
Differences from BASICA
- In this version of BASIC, VARPTR$ must be used in the DRAW and PLAY statements to execute substrings containing variables.
- BASICA supports both the VARPTR$ syntax and the syntax containing just the variable name.
Example
This example uses the PLAY statements and the PLAY and VARPTR$ functions to play continuous music by calling an event-handling subroutine when the background music buffer goes from three to two notes.
CLS
'Call subroutine Replay when the music buffer goes from 3 to 2 notes.
ON PLAY(3) GOSUB Replay
'Turn on event trapping for PLAY.
PLAY ON
'Define a string containing the melody.
FElise$ = "o3 L8 E D+ E D+ E o2 B o3 D C L2 o2 A"
PLAY "MB X" + VARPTR$(FElise$)
'Suspend event trapping until next PLAY ON but remember events that occur
'while event trapping is disabled.
PLAY STOP
'Introduce a variable-length delay.
LOCATE 23, 1: PRINT "Press any key to continue."
DO
LOOP WHILE INKEY$ = ""
'Re-enable play event trapping remembering that a PLAY event has occurred.
PLAY ON
LOCATE 23, 1: PRINT "Press any key to stop. "
'Loop until a key is pressed.
DO
GOSUB BackGround
LOOP WHILE INKEY$ = ""
'Disable PLAY event processing.
PLAY OFF
'Count down to 0 notes in the queue.
DO
GOSUB BackGround
LOOP UNTIL NoteCount = 0
END
'PLAY event-handling subroutine.
Replay:
'Increment and print a counter each time.
Count% = Count% + 1
LOCATE 3, 1: PRINT "Replay routine called"; Count%; "time(s)";
'PLAY it again to fill the buffer.
PLAY "MB X" + VARPTR$(FElise$)
RETURN
'Background music queue reporting subroutine.
BackGround:
'Get a notecount.
NoteCount = PLAY(0)
LOCATE 1, 1
PRINT "Background queue notes remaining --> "; NoteCount
'Loop until Notecount changes or equals 0.
DO
LOOP UNTIL NoteCount <> PLAY(0) OR NoteCount = 0
RETURN
See also: