CLEAR Can Cause "Subscript out of Range" with $DYNAMIC Array (67373)
The information in this article applies to:
- Microsoft QuickBASIC 4.0
- Microsoft QuickBASIC 4.0b
- Microsoft QuickBASIC 4.5
- Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
- Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
- Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
- Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1
- Microsoft GW-BASIC 3.2
- Microsoft GW-BASIC 3.22
- Microsoft GW-BASIC 3.23
This article was previously published under Q67373 SUMMARY
Increasing the stack space with the CLEAR statement also reinitializes
all variables. This includes erasing the memory for any $DYNAMIC
arrays and initializing the elements of a $STATIC array to zero or
null strings. For this reason, CLEAR should normally be used only as
the very first executable statement in a program. Using it anywhere
else can cause problems. For example, once you have used CLEAR, if you
attempt to access an element of a $DYNAMIC array, the error "Subscript
out of range" will be generated. This is expected behavior because the
CLEAR statement deallocates all memory for the dynamic array. After a
CLEAR, all $DYNAMIC arrays must be re-created with the REDIM
statement.
This information applies to Microsoft QuickBasic versions 2.0, 2.01,
3.0, 4.0, 4.0b, and 4.5 for MS-DOS; Microsoft Basic Compiler versions
6.0 and 6.0b for MS-DOS and MS OS/2; Microsoft Basic Professional
Development System (PDS) versions 7.0 and 7.1 for MS-DOS and MS OS/2;
and all versions of GW-Basic (such as 3.2, 3.22, and 3.23) for MS-DOS.
Modification Type: | Minor | Last Reviewed: | 8/16/2005 |
---|
Keywords: | KB67373 |
---|
|