Difference between revisions of "$DYNAMIC"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 7: Line 7:
  
  
* All [[Metacommand]]s require a REM or apostrophy (') before them and are normally placed at the start of the main module.
+
* Qbasic [[Metacommand]]s require a REM or apostrophy (') before them and are always placed at the start of the main module.
 +
* '''QB64''' does not require a comment or [[REM]] before any [[Metacommand]]. '''Do NOT comment QB64 specific [[Metacommand]]s!'''
 
* Dynamic arrays can be resized using [[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 [[REDIM]]ensioned except when [[_PRESERVE]] is used in QB64 only.
 
* All data in the array will be lost when [[REDIM]]ensioned except when [[_PRESERVE]] is used in QB64 only.

Revision as of 15:28, 14 August 2012

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


Syntax

REM $DYNAMIC


  • Qbasic Metacommands require a REM or apostrophy (') before them and are always placed at the start of the main module.
  • QB64 does not require a comment or REM before any Metacommand. Do NOT comment QB64 specific Metacommands!
  • Dynamic arrays can be resized using REDIM. The array's type cannot be changed.
  • All data in the array will be lost when REDIMensioned except when _PRESERVE is used in QB64 only.
  • REDIM _PRESERVE can preserve and may move the previous array data when the array boundaries change.
  • _PRESERVE allows the upper and lower boundaries of an array to be changed. The number of dimensions cannot change!
  • 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 as the arrays are removed completely.


Example: REDIMing a $DYNAMIC array using _PRESERVE to retain previous array values.

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

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


See also:



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