Difference between revisions of "$DYNAMIC"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 8: Line 8:
 
* Metacommands require a REM or apostrophy (') before them.
 
* Metacommands require a REM or apostrophy (') before them.
 
* Metacommands should be placed at the program start in the main module.
 
* Metacommands should be placed at the program start in the main module.
* Dynamic arrays can be resized using {{KW|REDIM}}. The array's type cannot be changed.
+
* Dynamic arrays can be resized using [[REDIM]]. The array's type cannot be changed.
 
* All data in the array will be lost when redimensioned in QBasic.
 
* All data in the array will be lost when redimensioned in QBasic.
 
* In '''QB64''', REDIM [[_PRESERVE]] can preserve and move the previous array data when the array boundaries change.
 
* In '''QB64''', REDIM [[_PRESERVE]] can preserve and move the previous array data when the array boundaries change.
Line 38: Line 38:
  
 
''See also:''  
 
''See also:''  
* {{KW|$STATIC}}, {{KW|$INCLUDE}}, {{KW|Metacommand}}
+
* [[$STATIC]], [[$INCLUDE]], [[Metacommand]]
 
+
* [[DIM]], [[REDIM]], [[Arrays]]
* {{KW|DIM}}, {{KW|Arrays}}
 
  
  

Revision as of 01:14, 4 May 2011

The $DYNAMIC Metacommand allows the creation of dynamic(changeable) array sizes.


== Syntax == REM $DYNAMIC


  • Metacommands require a REM or apostrophy (') before them.
  • Metacommands should be placed at the program start in the main module.
  • Dynamic arrays can be resized using REDIM. The array's type cannot be changed.
  • All data in the array will be lost when redimensioned in QBasic.
  • In QB64, REDIM _PRESERVE can preserve and move the previous array data when the array boundaries change.
  • _PRESERVE allows the upper and lower boundaries of an array to be changed.
  • Dynamic arrays can also be resized by the program user's input if desired.
  • Dynamic arrays MUST be REDIMensioned if ERASE or CLEAR are used to clear the array values.


Example: Re-dimensioning a $DYNAMIC array using _PRESERVE.

REM $DYNAMIC 'create dynamic arrays only DIM array(10) 'create array with 11 elements FOR i = 0 TO 10 array(i) = i: PRINT array(i); 'set and display element values NEXT PRINT REDIM _PRESERVE array(10 TO 20) FOR i = 10 TO 20 PRINT array(i); NEXT END

1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10


See also:




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