The information in this article applies to:
SUMMARYThis article gives suggestions on how to work around the following errors: These suggestions apply to both interpreted and compiled programs. MORE INFORMATIONDiagnosing Near Heap DepletionThe error "Out of memory" happens when you run out of either near heap or far heap space. Usually, you run out of near heap space. Determine which area is depleted by printing out the amount of free space in each area as shown below:
If you find that you have the same amount of free hear and far heap space,
far heap is depleted. You should print these values as near as possible to
the point in your program immediately before the "Out of memory" error
occurs.
Increasing Free Near HeapAdd the REM $DYNAMIC (or '$DYNAMIC) statement to the top of each module and form. This statement allows you to change the number of elements in your arrays at run time (by using REDIM). Even more important, the statement causes the arrays to store in far heap rather than near heap. Arrays of variable-length strings are an exception; they are always in the near heap whether or not they are dynamic.
Convert arrays of variable-length strings into arrays of fixed-length
strings to allow REM $DYNAMIC to store this data in far heap. For
example:
Use the RTRIM$ function to remove trailing spaces from fixed-length
strings when you retrieve them from the array. For example
Using fixed-length arrays typically increases the storage required for
each string because space is reserved for the maximum possible length. If
you require an array larger than 64K, invoke the interpreter or compiler
with the /Ah option. Otherwise you receive "Subscript out of range,"
error 9.
VBDOS /Ah -- Visual Basic for MS-DOSIf you require an array larger than 128K, specify the length for each string in the array as a power of 2 (2, 4, 8, 16, 32, and so on). otherwise you receive the error "Subscript out of range."
Create arrays of one element out of large variables that are not already
arrays and are not variable-length strings. This causes REM $DYNAMIC to
store them in far heap rather than near heap. User defined type variables
and fixed-length strings are good candidates. For example,
After adding REM $DYNAMIC to a support module (a .BAS file other than
your start-up file), you may encounter a side effect problem with the
symptom of error "Subscript out of range." This happens on arrays
defined with DIM SHARED at the module level of a support module.
Similarly, after adding REM $DYNAMIC to a form, you may encounter the
error "Executable code not allowed in module level of a form." These
errors are due to REM $DYNAMIC changing DIM SHARED from a compile-time
statement to a run-time statement for arrays.
To work around the "Subscript out of range" side effect problem, define the array at the module level and allocate the array in a SUB or FUNCTION. Use a STATIC variable to keep track of whether the array has been allocated. For example:
To work around the Visual Basic error "Executable code not allowed in
module level of a form," define the array at the module level and use
REDIM to allocate the array from the Form_Load event handler.
Additional query words: VBmsdos QuickBas BasicCom B_VBmsdos 1.00 b_basiccom 7.10 b_quickbas 4.50
Keywords : |
Last Reviewed: December 4, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |