Difference between revisions of "VARPTR$"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
Line 8: Line 8:
  
  
''Example:'' Using the function to change a Turn Angle value in DRAW.
+
''Example:'' Using the function to change a Turn Angle value using DRAW.
{{CodeStart}}
+
{{CodeStart}} '' ''
{{Cl|DRAW}} "TA=" + {{Cl|VARPTR$}}(angle)
+
{{Cl|SCREEN (statement)|SCREEN}} 12
 +
                          'Demonstrates how string DRAW angles are used with TA
 +
{{Cl|FOR...NEXT|FOR}} i = 0 {{Cl|TO}} 360 {{Cl|STEP}} 30          'mark clock hours every 30 degrees
 +
  angle$ = {{Cl|STR$}}(i)                'change degree value i to a string 
 +
  {{Cl|PSET}} (175, 250), 6              'clock center
 +
  {{Cl|DRAW}} "TA" + angle$ + "BU100"    'add string angle to Turn Angle and draw blind up
 +
  {{Cl|CIRCLE}} {{Cl|STEP}}(0, 0), 5, 12        'place a circle at end of Up line
 +
  {{Cl|DRAW}} "P9, 12"
 +
  {{Cl|_DELAY}} .5         
 +
{{Cl|NEXT}}
 +
                            'Demonstrates how VARPTR$ is used with TA=
 +
{{Cl|DO}}: sec$ = {{Cl|RIGHT$}}({{Cl|TIME$}}, 2)        'get current second value from time
 +
  degree = {{Cl|VAL}}(sec$) * -6          'use a negative value to Turn Angle clockwise
 +
  {{Cl|PSET}} (175, 250), 9              'clock center
 +
  {{Cl|DRAW}} "TA=" + {{Cl|VARPTR$}}(degree) + "U90"  'VARPTR$ values requires = in DRAW and PLAY
 +
  {{Cl|DO}}: {{Cl|_LIMIT}} 30: {{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|RIGHT$}}({{Cl|TIME$}}, 2) <> sec$  'loop until seconds value changes
 +
  {{Cl|IF}} {{Cl|INKEY$}} <> "" {{Cl|THEN}} {{Cl|EXIT DO}}
 +
  {{Cl|PSET}} (175, 250), 0
 +
  {{Cl|DRAW}} "TA=" + {{Cl|VARPTR$}}(degree) + "U90"  'erase previous second hand draw
 +
{{Cl|LOOP}} '' ''
 
{{CodeEnd}}
 
{{CodeEnd}}
 +
:''Explanation:'' When the VARPTR$ value is used in DRAW and PLAY '''=''' MUST be used to pass the value to the draw! Negative Turn Angle values move clockwise and each second moves the hand 6 degrees. '''TA''' uses actual degree angles starting at 0 or noon.
 +
  
  

Revision as of 05:23, 19 October 2010

VARPTR$ is a memory function that returns a STRING representation of a variable's memory address value for use in a DRAW or PLAY statement.


Syntax: value$ = VARPTR(variable_name)


  • When using this function with DRAW or PLAY strings, use an = sign.


Example: Using the function to change a Turn Angle value using DRAW.

SCREEN 12 'Demonstrates how string DRAW angles are used with TA FOR i = 0 TO 360 STEP 30 'mark clock hours every 30 degrees angle$ = STR$(i) 'change degree value i to a string PSET (175, 250), 6 'clock center DRAW "TA" + angle$ + "BU100" 'add string angle to Turn Angle and draw blind up CIRCLE STEP(0, 0), 5, 12 'place a circle at end of Up line DRAW "P9, 12" _DELAY .5 NEXT 'Demonstrates how VARPTR$ is used with TA= DO: sec$ = RIGHT$(TIME$, 2) 'get current second value from time degree = VAL(sec$) * -6 'use a negative value to Turn Angle clockwise PSET (175, 250), 9 'clock center DRAW "TA=" + VARPTR$(degree) + "U90" 'VARPTR$ values requires = in DRAW and PLAY DO: _LIMIT 30: LOOP UNTIL RIGHT$(TIME$, 2) <> sec$ 'loop until seconds value changes IF INKEY$ <> "" THEN EXIT DO PSET (175, 250), 0 DRAW "TA=" + VARPTR$(degree) + "U90" 'erase previous second hand draw LOOP

Explanation: When the VARPTR$ value is used in DRAW and PLAY = MUST be used to pass the value to the draw! Negative Turn Angle values move clockwise and each second moves the hand 6 degrees. TA uses actual degree angles starting at 0 or noon.


See also:



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page