FIX: Erase Won't Clear Contents of Huge Fixed Array as Variant
ID: Q99457
|
The information in this article applies to:
-
Microsoft Visual Basic Standard and Professional Editions for Windows, versions 2.0, 3.0
SYMPTOMS
The Erase statement fails to erase huge static arrays of type Variant. This
problem occurs with the Variant data type only.
The problem does not occur if the size of the array is less than 64K or if
you use a huge dynamic array of type Variant.
CAUSE
This problem occurs with huge static arrays of the variant data type. An
array is static when you dimension it with the Static keyword or if you
use the DIM keyword to dimension the array in the general-declaration
section of a form or module.
The problem occurs because the Erase statement corrupts the array
descriptor for a huge static array of variants. However, only the
references to the 64K data segments other than the first segment are
corrupted. Any elements in the first 64K segment of the array are always
erased properly. All elements stored in other segments are not erased.
The Erase statement is only effective the first time you erase the elements
of a huge static variant array. Any additional attempt to Erase elements
of the array will fail and the elements in the array in data segments other
than the first segment will not be erased.
WORKAROUND
To work around the problem, clear each element of the array manually by
setting each element to Empty. Replace the "Erase a" statement in step 2
shown below with this code:
For i% = 0 to 5000
a(i%) = Empty '** Empty = 0
Next i%
STATUS
Microsoft has confirmed this to be a bug in Microsoft Visual Basic
version 2.0 for Windows. This problem was corrected in Microsoft Visual
Basic version 3.0 for Windows.
MORE INFORMATION
Steps to Reproduce Problem
- Start Visual Basic, or choose New Project from the File menu (ALT, F, N)
if Visual Basic is already running. Form1 is created by default.
- Enter the following procedure into the general section of Form1:
Sub test()
Static a(5000) As Variant 'Huge static variant array
a(1) = 1 '*element 1 is in the first segment
a(100) = 2 '*element 100 is in the first segment
a(5000) = 3 '*element 5000 is in the second segment
Debug.Print "Before the Erase:"
Debug.Print "a(1) = "; a(1)
Debug.Print "a(100) = "; a(100)
Debug.Print "a(5000) = "; a(5000)
Debug.Print ""
Erase a '*erase the elements
Debug.Print "After the Erase:"
Debug.Print "a(1) = "; a(1)
Debug.Print "a(100) = "; a(100)
Debug.Print "a(5000) = "; a(5000)
Debug.Print ""
End Sub
- Place the following code in the Form_Click event procedure for Form1:
Form_Click ()
Call test
End Sub
- Press F5 to run the example. Click Form1 to see the following results
in the Debug Window:
Before the Erase:
a(1) = 1
a(100) = 2
a(5000) = 3
After the Erase:
a(1) =
a(100) =
a(5000) =
But if you click again, you will see different results:
Before the Erase
a(1) = 1
a(100) = 2
a(5000) = 3
After the Erase
a(1) =
a(100) =
a(5000) = 3
This shows that the elements of the huge static Variant array were not
cleared, but the elements of a smaller Variant array were cleared.
Additional query words:
buglist2.00 fixlist3.00 1.00
Keywords :
Version :
Platform :
Issue type :