$STATIC: 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
TheSnowDog (talk | contribs) m (QBasic capitalisation) Tag: visualeditor |
No edit summary Tag: Manual revert |
||
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The | The [[$STATIC]] [[Metacommand|metacommand]] allows the creation of static (unresizable) arrays. | ||
{{PageSyntax}} | {{PageSyntax}} | ||
: | :{[[REM]] | [[apostrophe|']] } [[$STATIC]] | ||
{{PageDescription}} | |||
* QBasic [[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 normally placed at the start of the main module. | ||
* Static arrays cannot be resized. If a variable is used to size any array, it becomes [[$DYNAMIC]]. | * Static arrays cannot be resized. If a variable is used to size any array, it becomes [[$DYNAMIC]]. | ||
* A [[REDIM]] statement has no effect on [[$STATIC]] arrays except perhaps a [[ERROR Codes|duplicate definition error]] at the [[REDIM]] | * A [[REDIM]] statement has no effect on [[$STATIC]] arrays except perhaps a [[ERROR Codes|duplicate definition error]] at the [[REDIM]] statement. | ||
* The array's type cannot be changed once [[DIM]] and a literal value sets the dimensions and element size. | * The array's type cannot be changed once [[DIM]] and a literal value sets the dimensions and element size. | ||
* [[$STATIC]] defined program [[arrays]] cannot be [[REDIM|re-sized]] or use [[_PRESERVE]]. | * [[$STATIC]] defined program [[arrays]] cannot be [[REDIM|re-sized]] or use [[_PRESERVE]]. | ||
{{PageExamples}} | |||
''Example:'' When a variable is used, the array can be resized despite $STATIC. The array becomes [[$DYNAMIC]]. | ''Example:'' When a variable is used, the array can be resized despite $STATIC. The array becomes [[$DYNAMIC]]. | ||
{{CodeStart}} | {{CodeStart}} | ||
'{{Cl|$STATIC}} | '{{Cl|$STATIC}} | ||
Line 23: | Line 24: | ||
{{Cl|REDIM}} array(2 * size) | {{Cl|REDIM}} array(2 * size) | ||
{{Cl|PRINT}} {{Cl|UBOUND}}(array) | {{Cl|PRINT}} {{Cl|UBOUND}}(array) | ||
{{CodeEnd}} | {{CodeEnd}} | ||
: ''Note:'' [[DIM]] using a literal numerical size will create a Duplicate definition error. | : ''Note:'' [[DIM]] using a literal numerical size will create a Duplicate definition error. | ||
{{PageSeeAlso}} | |||
* [[$DYNAMIC]], [[STATIC]] | * [[$DYNAMIC]], [[STATIC]] | ||
* [[Arrays]], [[Metacommand]] | * [[Arrays]], [[Metacommand]] |
Latest revision as of 01:02, 23 January 2023
The $STATIC metacommand allows the creation of static (unresizable) arrays.
Syntax
Description
- QBasic Metacommands require a REM or apostrophy (') before them and are normally placed at the start of the main module.
- Static arrays cannot be resized. If a variable is used to size any array, it becomes $DYNAMIC.
- A REDIM statement has no effect on $STATIC arrays except perhaps a duplicate definition error at the REDIM statement.
- The array's type cannot be changed once DIM and a literal value sets the dimensions and element size.
- $STATIC defined program arrays cannot be re-sized or use _PRESERVE.
Examples
Example: When a variable is used, the array can be resized despite $STATIC. The array becomes $DYNAMIC.
'$STATIC INPUT "Enter array size: ", size DIM array(size) 'using an actual number instead of the variable will create an error! REDIM array(2 * size) PRINT UBOUND(array) |
- Note: DIM using a literal numerical size will create a Duplicate definition error.
See also