CLEAR: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "The CLEAR statement clears all variable and array element values in a program. {{PageSyntax}} : CLEAR [, {{Parameter|ignored&}} , {{Parameter|ignored&}}] {{PageDescription}} * All parameters are optional and ignored by '''QB64'''. * Normally used to clear all program variable and array values where numerical values become zero and string values become empty (""). * It does not clear constant values. * Closes all opened files. * $DYNAMIC...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 16: Line 16:
{{PageExamples}}
{{PageExamples}}
''Example:'' Using CLEAR to clear array elements from [[STATIC|static]] arrays or arrays created using [[DIM]].
''Example:'' Using CLEAR to clear array elements from [[STATIC|static]] arrays or arrays created using [[DIM]].
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|CLS}}
{{Cl|CLS}}
{{Cl|DIM}} array(10)  'create a {{Cl|$STATIC}} array
{{Cl|DIM}} array(10)  'create a {{Cl|$STATIC}} array
Line 25: Line 25:
{{Cl|CLEAR}}
{{Cl|CLEAR}}


{{Cl|PRINT}} array(5) '' ''
{{Cl|PRINT}} array(5)
{{CodeEnd}}
{{CodeEnd}}
:''Note:'' If you change DIM to REDIM a "Subscript out of range" error will occur because a [[$DYNAMIC]] array is removed by CLEAR.
:''Note:'' If you change DIM to REDIM a "Subscript out of range" error will occur because a [[$DYNAMIC]] array is removed by CLEAR.
Line 31: Line 31:


{{PageSeeAlso}}
{{PageSeeAlso}}
* [https://qb64phoenix.com/forum/showthread.php?tid=1223 Featured in our "Keyword of the Day" series]
* [[ERASE]]
* [[ERASE]]
* [[REDIM]], [[_PRESERVE]]
* [[REDIM]], [[_PRESERVE]]
* [[Arrays]], [[&B|_BIT arrays]]
* [[Arrays]]




{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 22:20, 18 June 2024

The CLEAR statement clears all variable and array element values in a program.


Syntax

CLEAR [, ignored& , ignored&]


Description

  • All parameters are optional and ignored by QB64.
  • Normally used to clear all program variable and array values where numerical values become zero and string values become empty ("").
  • It does not clear constant values.
  • Closes all opened files.
  • $DYNAMIC or REDIM arrays will need to be redimensioned or an error will occur when referenced because they are removed.


Examples

Example: Using CLEAR to clear array elements from static arrays or arrays created using DIM.

CLS
DIM array(10)   'create a $STATIC array
array(5) = 23

PRINT array(5)

CLEAR

PRINT array(5)
Note: If you change DIM to REDIM a "Subscript out of range" error will occur because a $DYNAMIC array is removed by CLEAR.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link