$DYNAMIC: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "The $DYNAMIC metacommand allows the creation of dynamic (changeable) arrays. {{PageSyntax}} :{REM | ' } $DYNAMIC {{PageDescription}} * QBasic metacommands require REM or apostrophe (') before them and are always placed at the start of 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 except whe...") |
No edit summary |
||
Line 1: | Line 1: | ||
The [[$DYNAMIC]] [[Metacommand|metacommand]] allows the creation of dynamic ( | The [[$DYNAMIC]] [[Metacommand|metacommand]] allows the creation of dynamic (resizable) arrays. | ||
{{PageSyntax}} | {{PageSyntax}} | ||
:{[[REM]] | ' } [[$DYNAMIC]] | :{[[REM]] | [[apostrophe|']] } [[$DYNAMIC]] | ||
{{PageDescription}} | {{PageDescription}} | ||
* QBasic [[Metacommand|metacommands]] require [[REM]] or [[Apostrophe|apostrophe]] (') before them and are | * QBasic [[Metacommand|metacommands]] require [[REM]] or [[Apostrophe|apostrophe]] (') before them and are normally placed at the start of the main module. | ||
* 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. | * All data in the array will be lost when [[REDIM]]ensioned except when [[_PRESERVE]] is used. | ||
Line 17: | Line 17: | ||
{{PageExamples}} | {{PageExamples}} | ||
''Example:'' [[REDIM]]ing a $DYNAMIC array using [[_PRESERVE]] to retain previous array values. | ''Example:'' [[REDIM]]ing a $DYNAMIC array using [[_PRESERVE]] to retain previous array values. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|REM}} {{Cl|$DYNAMIC}} 'create dynamic arrays only | {{Cl|REM}} {{Cl|$DYNAMIC}} 'create dynamic arrays only | ||
{{Cl|DIM}} array(10) 'create array with 11 elements | {{Cl|DIM}} array(10) 'create array with 11 elements | ||
Line 28: | Line 28: | ||
{{Cl|PRINT}} array(i); | {{Cl|PRINT}} array(i); | ||
{{Cl|NEXT}} | {{Cl|NEXT}} | ||
{{Cl|END}} | {{Cl|END}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}}0 1 2 3 4 5 6 7 8 9 10 | {{OutputStart}}0 1 2 3 4 5 6 7 8 9 10 |
Revision as of 14:28, 11 June 2022
The $DYNAMIC metacommand allows the creation of dynamic (resizable) arrays.
Syntax
Description
- QBasic metacommands require REM or apostrophe (') before them and are normally placed at the start of 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 except when _PRESERVE is used.
- 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 must be REDIMensioned if ERASE or CLEAR are used as the arrays are removed completely.
Examples
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